Пример #1
0
 /**
  * Creates a new PurchaseOrder model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new PurchaseOrder();
     $model2 = new PurchaseOrderDetail();
     $newPODetail = new PurchaseOrderDetail();
     $product = Product::find()->where(['product_type' => 'p'])->orderBy('product_id')->all();
     $service = Product::find()->where(['product_type' => 's'])->orderBy('product_id')->all();
     $customer = Customer::find()->orderBy('customer_name')->all();
     $po = PurchaseOrder::find()->orderBy(['PurchaseOrder_id' => SORT_DESC])->one();
     $uid = Yii::$app->user->identity->user_id;
     $uname = Yii::$app->user->identity->user_name;
     if (isset($_POST['description'])) {
         $poDetailList = $_POST['description'];
         $customer_id = $_POST['customer-list'];
         $po_id = $_POST['po_id'];
         $po_no = $_POST['po_no'];
         $po_date = $_POST['po_date'];
         $productType = $_POST['productType'];
         $qty = $_POST['qty'];
         $unit = $_POST['unit'];
         $cost = $_POST['cost'];
         $hidden_price = $_POST['hidden_price'];
         $hidden_gst = $_POST['hidden_gst'];
         $hidden_tax_code = $_POST['hidden_tax_code'];
         $hidden_tax_rate = $_POST['hidden_tax_rate'];
         $hidden_price_gst = $_POST['hidden_price_gst'];
         $hidden_total = $_POST['hidden_total'];
         $hidden_gsttotal = $_POST['hidden_gsttotal'];
         $hidden_gstpricetotal = $_POST['hidden_gstpricetotal'];
         $hidden_product_name = $_POST['hidden_product_name'];
         if ($poDetailList != NULL) {
             $newPO = new PurchaseOrder();
             $newPO->purchaseorder_id = $po_id;
             $newPO->purchaseorder_no = $po_no;
             $newPO->purchaseorder_date = $po_date;
             $newPO->purchaseorder_date_transaction = $po_date;
             $newPO->purchaseorder_date_delete = $po_date;
             $newPO->purchaseorder_customerid = $customer_id;
             $newPO->purchaseorder_supplierid = 1;
             $newPO->purchaseorder_supplier_quotation_no = 11;
             $newPO->purchaseorder_createid = $uid;
             $newPO->purchaseorder_createname = $uname;
             $newPO->purchaseorder_remark = "lol";
             $newPO->purchaseorder_system = "y";
             $newPO->purchaseorder_partno = "y";
             $newPO->purchaseorder_charge = 123;
             $newPO->purchaseorder_update_stock_status = "y";
             $newPO->purchaseorder_status = "y";
             $newPO->purchaseorder_tax_label = "lol";
             $newPO->purchaseorder_tax_percent = 1;
             $newPO->purchaseorder_tax_amount = 100;
             $newPO->purchaseorder_printed_status = "y";
             $newPO->purchaseorder_revision = 1;
             $newPO->purchaseorder_parts_total = $hidden_total;
             $newPO->purchaseorder_deleteid = 1;
             $newPO->purchaseorder_payment_status = "y";
             $newPO->purchaseorder_no_user_format = "lol";
             $newPO->purchaseorder_auto_generate = "y";
             $newPO->purchaseorder_creditorid = 1;
             $newPO->purchaseorder_purchase_return = 123;
             $newPO->purchaseorder_payment_paid_thus_far = 123;
             $newPO->purchaseorder_outstanding_amount = 123;
             $newPO->purchaseorder_projectid = 1;
             $newPO->purchaseorder_gst_payable = $hidden_gsttotal;
             $newPO->purchaseorder_total_amount = $hidden_gstpricetotal;
             $newPO->save();
             foreach ($poDetailList as $key => $n) {
                 if ($n != NULL) {
                     if ($unit[$key] == NULL) {
                         $unit[$key] = "-";
                     }
                     $newPODetail = new PurchaseOrderDetail();
                     $newPODetail->purchaseorderdetail_purchaseorderid = $po_id;
                     $newPODetail->purchaseorderdetail_productid = $n;
                     $newPODetail->purchaseorderdetail_partno = "lol";
                     $newPODetail->purchaseorderdetail_productname = $hidden_product_name[$key];
                     $newPODetail->purchaseorderdetail_unit = $qty[$key];
                     $newPODetail->purchaseorderdetail_unitname = $unit[$key];
                     $newPODetail->purchaseorderdetail_product_cost = $cost[$key];
                     $newPODetail->purchaseorderdetail_price = $hidden_price[$key];
                     $newPODetail->purchaseorderdetail_unitsent = 0;
                     $newPODetail->purchaseorderdetail_status = "y";
                     $newPODetail->purchaseorderdetail_tax_code = $hidden_tax_code[$key];
                     $newPODetail->purchaseorderdetail_tax_rate = $hidden_tax_rate[$key];
                     $newPODetail->purchaseorderdetail_tax_amount = $hidden_gst[$key];
                     $newPODetail->purchaseorderdetail_total_amount = $hidden_price_gst[$key];
                     $newPODetail->purchaseorderdetail_gst_status = 1;
                     $newPODetail->save();
                 }
             }
         }
     }
     if ($newPODetail->save()) {
         return $this->redirect(['index']);
     } elseif ($newPODetail->load(Yii::$app->request->post())) {
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model, 'model2' => $model2, 'product' => $product, 'service' => $service, 'customer' => $customer, 'po' => $po, 'model2' => $model2, 'product' => $product, 'service' => $service, 'customer' => $customer, 'po' => $po]);
     }
 }
 /**
  * Creates a new PurchaseOrder model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new PurchaseOrder();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }