You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClientResource.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <?php
  2. namespace App\Filament\Company\Resources\Common;
  3. use App\Filament\Company\Resources\Common\ClientResource\Pages;
  4. use App\Filament\Forms\Components\CreateCurrencySelect;
  5. use App\Filament\Forms\Components\PhoneBuilder;
  6. use App\Models\Common\Client;
  7. use Filament\Forms;
  8. use Filament\Forms\Form;
  9. use Filament\Resources\Resource;
  10. use Filament\Tables;
  11. use Filament\Tables\Table;
  12. class ClientResource extends Resource
  13. {
  14. protected static ?string $model = Client::class;
  15. public static function form(Form $form): Form
  16. {
  17. return $form
  18. ->schema([
  19. Forms\Components\Section::make('General Information')
  20. ->schema([
  21. Forms\Components\TextInput::make('name')
  22. ->label('Client Name')
  23. ->required()
  24. ->maxLength(255),
  25. CreateCurrencySelect::make('currency_code')
  26. ->disabledOn('edit')
  27. ->relationship('currency', 'name'),
  28. Forms\Components\TextInput::make('account_number')
  29. ->maxLength(255),
  30. Forms\Components\TextInput::make('website')
  31. ->maxLength(255),
  32. Forms\Components\Textarea::make('notes')
  33. ->columnSpanFull(),
  34. ])->columns(),
  35. Forms\Components\Section::make('Primary Contact')
  36. ->relationship('primaryContact')
  37. ->schema([
  38. Forms\Components\Hidden::make('is_primary')
  39. ->default(true),
  40. Forms\Components\TextInput::make('first_name')
  41. ->label('First Name')
  42. ->required()
  43. ->maxLength(255),
  44. Forms\Components\TextInput::make('last_name')
  45. ->label('Last Name')
  46. ->required()
  47. ->maxLength(255),
  48. Forms\Components\TextInput::make('email')
  49. ->label('Email')
  50. ->required()
  51. ->email()
  52. ->maxLength(255),
  53. PhoneBuilder::make('phones')
  54. ->hiddenLabel()
  55. ->blockLabels(false)
  56. ->default([
  57. ['type' => 'office'],
  58. ])
  59. ->blocks([
  60. Forms\Components\Builder\Block::make('office')
  61. ->label('Office')
  62. ->schema([
  63. Forms\Components\TextInput::make('number')
  64. ->label('Office')
  65. ->required()
  66. ->maxLength(15),
  67. ])->maxItems(1),
  68. Forms\Components\Builder\Block::make('mobile')
  69. ->label('Mobile')
  70. ->schema([
  71. Forms\Components\TextInput::make('number')
  72. ->label('Mobile')
  73. ->required()
  74. ->maxLength(15),
  75. ])->maxItems(1),
  76. Forms\Components\Builder\Block::make('toll_free')
  77. ->label('Toll Free')
  78. ->schema([
  79. Forms\Components\TextInput::make('number')
  80. ->label('Toll Free')
  81. ->required()
  82. ->maxLength(15),
  83. ])->maxItems(1),
  84. Forms\Components\Builder\Block::make('fax')
  85. ->label('Fax')
  86. ->schema([
  87. Forms\Components\TextInput::make('number')
  88. ->label('Fax')
  89. ->live()
  90. ->maxLength(15),
  91. ])->maxItems(1),
  92. ])
  93. ->deletable(fn (PhoneBuilder $builder) => $builder->getItemsCount() > 1)
  94. ->reorderable(false)
  95. ->blockNumbers(false)
  96. ->addActionLabel('Add Phone'),
  97. ]),
  98. Forms\Components\Repeater::make('secondaryContacts')
  99. ->relationship()
  100. ->columnSpanFull()
  101. ->hiddenLabel()
  102. ->defaultItems(0)
  103. ->addActionLabel('Add Contact')
  104. ->schema([
  105. Forms\Components\TextInput::make('first_name')
  106. ->label('First Name')
  107. ->required()
  108. ->maxLength(255),
  109. Forms\Components\TextInput::make('last_name')
  110. ->label('Last Name')
  111. ->required()
  112. ->maxLength(255),
  113. Forms\Components\TextInput::make('email')
  114. ->label('Email')
  115. ->required()
  116. ->email()
  117. ->maxLength(255),
  118. PhoneBuilder::make('phones')
  119. ->hiddenLabel()
  120. ->blockLabels(false)
  121. ->default([
  122. ['type' => 'office'],
  123. ])
  124. ->blocks([
  125. Forms\Components\Builder\Block::make('office')
  126. ->label('Office')
  127. ->schema([
  128. Forms\Components\TextInput::make('number')
  129. ->label('Office')
  130. ->required()
  131. ->maxLength(255),
  132. ])->maxItems(1),
  133. ])
  134. ->addable(false)
  135. ->deletable(false)
  136. ->reorderable(false)
  137. ->blockNumbers(false),
  138. ]),
  139. Forms\Components\Section::make('Billing')
  140. ->relationship('billingAddress')
  141. ->schema([
  142. Forms\Components\Hidden::make('type')
  143. ->default('billing'),
  144. Forms\Components\TextInput::make('address_line_1')
  145. ->label('Address Line 1')
  146. ->required()
  147. ->maxLength(255),
  148. Forms\Components\TextInput::make('address_line_2')
  149. ->label('Address Line 2')
  150. ->maxLength(255),
  151. Forms\Components\TextInput::make('city')
  152. ->label('City')
  153. ->required()
  154. ->maxLength(255),
  155. Forms\Components\TextInput::make('state')
  156. ->label('State')
  157. ->required()
  158. ->maxLength(255),
  159. Forms\Components\TextInput::make('postal_code')
  160. ->label('Postal Code / Zip Code')
  161. ->required()
  162. ->maxLength(255),
  163. Forms\Components\TextInput::make('country')
  164. ->label('Country')
  165. ->required()
  166. ->maxLength(255),
  167. ])->columns(),
  168. Forms\Components\Section::make('Shipping')
  169. ->relationship('shippingAddress')
  170. ->schema([
  171. Forms\Components\Hidden::make('type')
  172. ->default('shipping'),
  173. Forms\Components\TextInput::make('recipient')
  174. ->label('Recipient')
  175. ->required()
  176. ->maxLength(255),
  177. Forms\Components\TextInput::make('address_line_1')
  178. ->label('Address Line 1')
  179. ->required()
  180. ->maxLength(255),
  181. Forms\Components\TextInput::make('address_line_2')
  182. ->label('Address Line 2')
  183. ->maxLength(255),
  184. Forms\Components\TextInput::make('city')
  185. ->label('City')
  186. ->required()
  187. ->maxLength(255),
  188. Forms\Components\TextInput::make('state')
  189. ->label('State')
  190. ->required()
  191. ->maxLength(255),
  192. Forms\Components\TextInput::make('postal_code')
  193. ->label('Postal Code / Zip Code')
  194. ->required()
  195. ->maxLength(255),
  196. Forms\Components\TextInput::make('country')
  197. ->label('Country')
  198. ->required()
  199. ->maxLength(255),
  200. Forms\Components\TextInput::make('phone')
  201. ->label('Phone')
  202. ->required()
  203. ->maxLength(255),
  204. Forms\Components\Textarea::make('notes')
  205. ->label('Delivery Instructions')
  206. ->maxLength(255)
  207. ->columnSpanFull(),
  208. ])->columns(),
  209. ]);
  210. }
  211. public static function table(Table $table): Table
  212. {
  213. return $table
  214. ->columns([
  215. Tables\Columns\TextColumn::make('company.name')
  216. ->numeric()
  217. ->sortable(),
  218. Tables\Columns\TextColumn::make('name')
  219. ->searchable(),
  220. Tables\Columns\TextColumn::make('currency_code')
  221. ->searchable(),
  222. Tables\Columns\TextColumn::make('account_number')
  223. ->searchable(),
  224. Tables\Columns\TextColumn::make('website')
  225. ->searchable(),
  226. ])
  227. ->filters([
  228. //
  229. ])
  230. ->actions([
  231. Tables\Actions\EditAction::make(),
  232. ])
  233. ->bulkActions([
  234. Tables\Actions\BulkActionGroup::make([
  235. Tables\Actions\DeleteBulkAction::make(),
  236. ]),
  237. ]);
  238. }
  239. public static function getRelations(): array
  240. {
  241. return [
  242. //
  243. ];
  244. }
  245. public static function getPages(): array
  246. {
  247. return [
  248. 'index' => Pages\ListClients::route('/'),
  249. 'create' => Pages\CreateClient::route('/create'),
  250. 'edit' => Pages\EditClient::route('/{record}/edit'),
  251. ];
  252. }
  253. }