Пример #1
0
 public function xuatkhoAction()
 {
     $aParam = $this->getParam();
     $kho = FacilityConsignmentAssocs::findFirst("facilityid='" . NHAKHO . "' AND consignmentid='" . $aParam['consignmentid'] . "'");
     if ($kho == true) {
         $aParam["updated_at"] = (new DateTime())->format('Y-m-d H:i:s');
         if ($aParam['quantity'] <= $kho->quantity) {
             $kho->quantity = $kho->quantity - $aParam['quantity'];
             $result = $kho->update();
             $cuahang = FacilityConsignmentAssocs::findFirst("facilityid='" . $aParam['facilityid'] . "' AND consignmentid='" . $aParam['consignmentid'] . "'");
             if ($cuahang == true) {
                 $cuahang->quantity = $cuahang->quantity + $aParam['quantity'];
                 $result_ = $cuahang->update();
             } else {
                 $aParam["created_at"] = (new DateTime())->format('Y-m-d H:i:s');
                 $new = new FacilityConsignmentAssocs();
                 $result_ = $new->save($aParam);
             }
             if ($result == true && $result_ == true) {
                 return $this->showErrorJson(1);
             } else {
                 return $this->showErrorJson(0, "Consignment", $aParam);
             }
         } else {
             return $this->showErrorJson(22, "Consignment", $aParam);
         }
     } else {
         return $this->showErrorJson(2, "Consignment", $aParam);
     }
 }
Пример #2
0
 public function editAction()
 {
     $aParam = $this->getParam();
     $check = Consignment::findFirst("(consignmentname_vi='" . $aParam['consignmentname_vi'] . "' OR consignmentname_en='" . $aParam['consignmentname_en'] . "') AND consignmentid<>'" . $aParam['consignmentid'] . "'");
     if ($check == false) {
         $aParam["updated_at"] = (new DateTime())->format('Y-m-d H:i:s');
         $update = Consignment::findFirst("consignmentid='" . $aParam['consignmentid'] . "'");
         $result = $update->update($aParam);
         $update_ = FacilityConsignmentAssocs::findFirst("facilityid='" . NHAKHO . "' AND consignmentid='" . $update->consignmentid . "'");
         $result_ = $update_->save($aParam);
         if ($result == true && $result_ == true) {
             $data = FacilityConsignmentAssocs::findFirst("facilityid='" . NHAKHO . "' AND consignmentid='" . $update->consignmentid . "'");
             return $this->showErrorJson(1, "Consignment", $data);
         } else {
             return $this->showErrorJson(0, "Consignment", $aParam);
         }
     } else {
         return $this->showErrorJson(2, "Consignment", $aParam);
     }
 }