Ejemplo n.º 1
0
 /**
  * Saved Data Purchasedetail | PO PLUS
  * @author ptrnov  <*****@*****.**>
  * @since 1.1
  */
 public function poplus_saved()
 {
     $poDetailModel = new Purchasedetail();
     if ($this->validate()) {
         $poDetailModel->KD_PO = $this->kD_PO;
         $poDetailModel->KD_RO = 'PurchasingPO';
         $poDetailModel->KD_BARANG = $this->kD_BARANG;
         $poDetailModel->NM_BARANG = $this->nM_BARANG;
         $poDetailModel->UNIT = $this->uNIT;
         $poDetailModel->NM_UNIT = $this->nM_UNIT;
         $poDetailModel->UNIT_QTY = $this->qTY_UNIT;
         $poDetailModel->UNIT_WIGHT = $this->wEIGHT_UNIT;
         $poDetailModel->QTY = $this->qTY;
         $poDetailModel->HARGA = $this->hARGA;
         $poDetailModel->STATUS = 0;
         $poDetailModel->STATUS_DATE = date("Y-m-d H:i:s");
         $poDetailModel->save();
         if ($poDetailModel->save()) {
             $this->PO_PLUS_RSLT = $poDetailModel->KD_PO;
             return $poDetailModel->KD_PO;
         }
         return $poDetailModel->KD_PO;
     }
     return null;
 }
Ejemplo n.º 2
0
 public function actionCk()
 {
     if (Yii::$app->request->isAjax) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $request = Yii::$app->request;
         $dataKeySelect = $request->post('keysSelect');
         $dataKdPo = $request->post('kdpo');
         $dataKdRo = $request->post('kdRo');
         $dataKdBrg = $request->post('kdBrg');
         /* Before Action -> 0 */
         $AryKdRo = ArrayHelper::map(Rodetail::find()->where(['KD_RO' => $dataKdRo])->andWhere('STATUS=101')->all(), 'ID', 'ID');
         //print_r($AryKdRo);
         $foreaceAryKdRo = $AryKdRo != 0 ? $AryKdRo : 'Array([0]=>"0")';
         foreach ($foreaceAryKdRo as $keyRo) {
             $roDetailHapus = Rodetail::findOne($keyRo);
             $roDetailHapus->TMP_CK = 0;
             $roDetailHapus->save();
         }
         $res = array('status' => 'true');
         /* An Action -> 0 */
         //print_r($dataKeySelect);
         if ($dataKeySelect != 0) {
             //$foreaceGvRoToPo=$dataKeySelect!=0? $dataKeySelect:'Array([0]=>"0")';
             foreach ($dataKeySelect as $idx) {
                 $roDetail = Rodetail::find()->where(['KD_RO' => $dataKdRo, 'ID' => $idx])->andWhere('STATUS=1')->one();
                 //STT =202
                 $poDetail = Purchasedetail::find()->where(['KD_PO' => $dataKdPo, 'KD_RO' => $dataKdRo, 'KD_BARANG' => $roDetail->KD_BARANG])->one();
                 $poUnit = $roDetail->cunit;
                 //$poBarangUmum=$roDetail->barangumum;
                 if (!$poDetail) {
                     //$roDetail = Rodetail::findOne($idx);
                     $roDetail->TMP_CK = 0;
                     /* Untuk testing Checkbook 1 | 0 */
                     //$roDetail->save();
                     $res = array('status' => true);
                     /* tidak ada Data pada Purchasedetail |KD_RO&KD_BARANG */
                     /*Save To Purchase detail*/
                     $poDetailModel = new Purchasedetail();
                     $poDetailModel->KD_PO = $dataKdPo;
                     $poDetailModel->KD_RO = $dataKdRo;
                     $poDetailModel->KD_BARANG = $roDetail->KD_BARANG;
                     $poDetailModel->NM_BARANG = $roDetail->NM_BARANG;
                     $poDetailModel->UNIT = $poUnit->KD_UNIT;
                     $poDetailModel->NM_UNIT = $poUnit->NM_UNIT;
                     $poDetailModel->UNIT_QTY = $poUnit->QTY;
                     $poDetailModel->UNIT_WIGHT = $poUnit->WEIGHT;
                     /*FORMULA*/
                     $pqtyTaken = "SELECT SUM(QTY) as QTY FROM p0002 WHERE KD_RO='" . $dataKdRo . "' AND KD_BARANG='" . $roDetail->KD_BARANG . "' GROUP BY KD_BARANG";
                     $countQtyTaken = Purchasedetail::findBySql($pqtyTaken)->one();
                     if ($countQtyTaken) {
                         $qtyInPo = $countQtyTaken->QTY != '' ? $countQtyTaken->QTY : 0;
                     } else {
                         $qtyInPo = 0;
                     }
                     //$qtyInPo=$countQtyTaken->QTY!=''? $countQtyTaken->QTY :0;
                     $actualQty = $roDetail->SQTY - $qtyInPo;
                     if ($actualQty > 0) {
                         $poDetailModel->QTY = $actualQty;
                     } else {
                         $poDetailModel->QTY = 0;
                     }
                     //if($roDetail->PARENT_ROSO==0){
                     $poDetailModel->HARGA = $roDetail->HARGA;
                     //RO
                     //}elseif($roDetail->PARENT_ROSO==1){
                     //	$poDetailModel->HARGA=$roDetail->HARGA_PABRIK; //SO
                     //}
                     $poDetailModel->STATUS = 0;
                     //$poDetailModel->STATUS_DATE =date;//\Yii::$app->formatter->asDate(date,'Y-M-d hh:mm:ss');
                     $roDetail->save();
                     $poDetailModel->save();
                 } else {
                     $res = array('status' => false);
                     /* sudah ada Data pada Purchasedetail |KD_RO&KD_BARANG */
                 }
             }
         }
         //$res = array('status' => 't');
         return $res;
     }
 }