Ejemplo n.º 1
0
 public function init()
 {
     $this->add(['name' => 'name', 'validators' => [FormUtil::notEmptyValidator(), FormUtil::noRecordExistsValidator('name', Menu::class, $this->em(), ['id' => $this->getRecordIdOrNull()])], 'filters' => []]);
     $this->add(['name' => 'description', 'required' => false, 'validators' => [], 'filters' => []]);
     $this->add(['name' => 'serving_unit', 'validators' => [FormUtil::notEmptyValidator()], 'filters' => []]);
     $this->add(['name' => 'note', 'required' => false, 'validators' => [], 'filters' => []]);
     $this->add(['name' => 'default_price', 'validators' => [FormUtil::notEmptyValidator(), FormUtil::floatValidator()], 'filters' => []]);
     $this->add(['name' => 'types', 'required' => false, 'validators' => [FormUtil::recordExistsValidator('id', Type::class, $this->em())], 'filters' => [FormUtil::entityReferenceCollectionFilter($this->em(), Type::class)]]);
     $this->add(['name' => 'parent', 'required' => false, 'validators' => [FormUtil::noRecordExistsValidator('id', Menu::class, $this->em()), FormUtil::callbackValidator(function ($input) {
         $id = $input instanceof Menu ? $input->getId() : $input;
         return in_array($id, $this->getParentMenuOptions());
     })], 'filters' => [FormUtil::entityReferenceFilter($this->em(), Menu::class)]]);
 }
Ejemplo n.º 2
0
 public function init()
 {
     $this->add(['name' => 'title', 'validators' => [FormUtil::notEmptyValidator()], 'filters' => []]);
     $this->add(['name' => 'warehouse', 'validators' => [FormUtil::notEmptyValidator(), FormUtil::recordExistsValidator('id', Warehouse::class, $this->em())], 'filters' => [FormUtil::entityReferenceFilter($this->em(), Warehouse::class)]]);
     $this->add(['name' => 'supplier_name', 'required' => false, 'validators' => [], 'filters' => []]);
     $this->add(['name' => 'currency', 'validators' => [FormUtil::notEmptyValidator()], 'filters' => []]);
     $this->add(['name' => 'note', 'required' => false, 'validators' => [], 'filters' => []]);
     $this->add(['name' => 'po_number', 'required' => false, 'validators' => [], 'filters' => []]);
     $this->add(['name' => 'status', 'validators' => [FormUtil::notEmptyValidator(), FormUtil::inArrayValidator(self::getStatusOptions()), FormUtil::workflowValidator(self::getStatusOptions(), $this->getRecordIdOrNull(), true)], 'filters' => []]);
     $this->add(['name' => 'ordered_at', 'validators' => [FormUtil::notEmptyValidator(), FormUtil::dateValidator('M d, Y')], 'filters' => [FormUtil::dateFilter('M d, Y', true)]]);
     $this->add(['name' => 'delivered_at', 'validators' => [FormUtil::notEmptyValidator(), FormUtil::dateValidator('M d, Y')], 'filters' => [FormUtil::dateFilter('M d, Y', true)]]);
     $this->add(['name' => 'raw_items', 'validators' => [FormUtil::notEmptyValidator("Belum ada item yang ditambahkan."), FormUtil::callbackValidator(function ($input) {
         if (!is_array($input)) {
             return false;
         }
         foreach ($input as $spec) {
             switch (true) {
                 case trim($spec['item_name']) == '':
                 case !is_numeric($spec['quantity']) || $spec['quantity'] < 0:
                 case !is_numeric($spec['total']) || $spec['total'] < 0:
                     return false;
             }
         }
         return true;
     }, "Qty. dan total harus valid setiap baris item.")], 'filters' => [FormUtil::callbackFilter(function ($input) {
         $return = [];
         if (is_array($input)) {
             $defaults = ['stock' => null, 'item_name' => '', 'quantity' => 0, 'unit' => 0, 'unit_price' => 0, 'subtotal' => 0, 'total' => 0];
             foreach ($input as $i => $spec) {
                 $spec += $defaults;
                 if ($spec['item_name']) {
                     // convert numbers
                     $spec['quantity'] = preg_replace('/[^0-9]/', null, $spec['quantity']);
                     $spec['unit_price'] = preg_replace('/[^0-9]/', null, $spec['unit_price']);
                     $spec['subtotal'] = preg_replace('/[^0-9]/', null, $spec['subtotal']);
                     $spec['total'] = preg_replace('/[^0-9]/', null, $spec['total']);
                     $return[] = $spec;
                 }
             }
         }
         return $return;
     })]]);
 }
Ejemplo n.º 3
0
 public function init()
 {
     $this->add(['name' => 'title', 'validators' => [FormUtil::notEmptyValidator()], 'filters' => []]);
     $this->add(['name' => 'outlet', 'validators' => [FormUtil::notEmptyValidator(), FormUtil::recordExistsValidator('id', Outlet::class, $this->em())], 'filters' => [FormUtil::entityReferenceFilter($this->em(), Outlet::class)]]);
     $this->add(['name' => 'currency', 'validators' => [FormUtil::notEmptyValidator()], 'filters' => []]);
     $this->add(['name' => 'type', 'validators' => [FormUtil::notEmptyValidator()], 'filters' => []]);
     $this->add(['name' => 'note', 'required' => false, 'validators' => [], 'filters' => []]);
     $this->add(['name' => 'ordered_at', 'validators' => [FormUtil::notEmptyValidator(), FormUtil::dateValidator('M d, Y')], 'filters' => [FormUtil::dateFilter('M d, Y')]]);
     $this->add(['name' => 'raw_items', 'validators' => [FormUtil::notEmptyValidator(), FormUtil::callbackValidator(function ($input) {
         if (!is_array($input)) {
             return false;
         }
         foreach ($input as $spec) {
             switch (true) {
                 case !is_numeric($spec['quantity']) || $spec['quantity'] < 0:
                 case !is_numeric($spec['subtotal']) || $spec['subtotal'] < 0:
                 case !is_numeric($spec['unit_price']) || $spec['unit_price'] < 0:
                 case !is_numeric($spec['total']) || $spec['total'] < 0:
                     return false;
             }
         }
         return true;
     }, "Qty. dan total harus valid setiap baris item.")], 'filters' => [FormUtil::callbackFilter(function ($input) {
         $return = [];
         if (is_array($input)) {
             $defaults = ['menu_price' => null, 'item_name' => '', 'quantity' => 0, 'unit_price' => 0, 'subtotal' => 0, 'total' => 0];
             foreach ($input as $i => $spec) {
                 $spec += $defaults;
                 if ($spec['item_name']) {
                     // convert numbers
                     $spec['quantity'] = preg_replace('/[^0-9]/', null, $spec['quantity']);
                     $spec['unit_price'] = preg_replace('/[^0-9]/', null, $spec['unit_price']);
                     $spec['subtotal'] = preg_replace('/[^0-9]/', null, $spec['subtotal']);
                     $spec['total'] = preg_replace('/[^0-9]/', null, $spec['total']);
                     $return[] = $spec;
                 }
             }
         }
         return $return;
     })]]);
 }