inwardgateregister_model = new Inwardgateregister_model(); $this->session = session(); helper('form'); //$this->load->library('form_validation'); $this->isLoggedIn(); } /** * This function used to load the first screen of the user */ public function index() { $this->global['pageTitle'] = 'Inward Gate Register'; $this->loadViews("viewinwardgateregister", $this->global, NULL, NULL); } function viewIGRDetails() { $this->global['pageTitle'] = 'Inward Gate Register Details'; $data['IGR'] = $this->inwardgateregister_model->igrListing(); $this->loadViews("viewIGRDetails", $this->global, $data, NULL); } function addinwardgateregister() { $this->inwardgateregister_model = new inwardgateregister_model(); $this->global['pageTitle'] = 'Add Inward Gate Register'; $result = $this->inwardgateregister_model->getpurchaseorder(); $data['PO_NO'] = array_filter($result, function($item) { return !($item->status === 'ST027' && $item->VaildUpto === null); }); $this->loadViews("inwardgateregister", $this->global, $data, NULL); } function addoutwardgateregister() { $this->inwardgateregister_model = new inwardgateregister_model(); $this->global['pageTitle'] = 'Add Outward Gate Register'; $data['Customer'] = $this->inwardgateregister_model->getCustomer(); $data['Supplier'] = $this->inwardgateregister_model->getSupplier(); //$data['Invoice'] = $this->inwardgateregister_model->getInvoice(); $data['storedmaterialcode'] = $this->inwardgateregister_model->getstoredmaterialcode(); //print_r($data['PO_NO']); $this->loadViews("ogr", $this->global, $data, NULL); } function ViewOgr() { $this->inwardgateregister_model = new inwardgateregister_model(); $this->global['pageTitle'] = 'View Outward Gate Register'; $data['OGR_Data'] = $this->inwardgateregister_model->getOGRData(); //print_r($data['OGR_Data']); $this->loadViews("ogrlist", $this->global, $data, NULL); } function EditOGR() { $OGRNO = $_GET['OGRNO']; $MRIRNO = $_GET['MRIRNO']; $this->global['pageTitle'] = 'View Outward Gate Register'; $data['OGR_Data'] = $this->inwardgateregister_model->getOGRDataforedit($OGRNO); $data['OGR_line'] = $this->inwardgateregister_model->getOGRlineDataforedit($OGRNO, $MRIRNO); $this->loadViews("editogr", $this->global, $data, NULL); } function GetInvoices() { $CustomerId = $this->request->getPost('customerId'); $data = $this->inwardgateregister_model->getInvoice($CustomerId); echo json_encode($data); } function GetPO() { $supplierId = $this->request->getPost('supplierId'); $data = $this->inwardgateregister_model->getPO($supplierId); echo json_encode($data); } function getPODetails() { $PONO = $this->request->getPost('PONO'); $data = $this->inwardgateregister_model->getPODetails($PONO); //$data['poout'] = $this->inwardgateregister_model->getPODetails($PONO); echo json_encode($data); } function getMRIRDetails() { $MRIRno = $this->request->getPost('mrirno'); $PONO = $this->request->getPost('PONO'); $materialcode = $this->request->getPost('materialcode'); $data = $this->inwardgateregister_model->getPOMRIRDetails($MRIRno, $PONO, $materialcode); //$data['outqty'] = $this->inwardgateregister_model->gettotalout($PONO,$materialcode); //$data['poout'] = $this->inwardgateregister_model->getPODetails($PONO); echo json_encode($data); } function getMRIR() { $MRIRno = $this->request->getPost('MRIRNO'); $PONO = $this->request->getPost('PONO'); $data = $this->inwardgateregister_model->getPOMRIRMaterial($MRIRno, $PONO); //$data['poout'] = $this->inwardgateregister_model->getPODetails($PONO); echo json_encode($data); } function getPOmrir() { $PONO = $this->request->getPost('PONO'); $data = $this->inwardgateregister_model->getPOmrir($PONO); //$data['poout'] = $this->inwardgateregister_model->getPODetails($PONO); echo json_encode($data); } function getPOmaterialDetails() { $PONO = $this->request->getPost('PONO'); $materialcode = $this->request->getPost('materialcode'); $data = $this->inwardgateregister_model->getPOmaterialDetails($PONO, $materialcode); echo json_encode($data); } function getPOmaterial() { $PONO = $this->request->getPost('PONO'); $data = $this->inwardgateregister_model->getPOmaterial($PONO); //$data['poout'] = $this->inwardgateregister_model->getPODetails($PONO); echo json_encode($data); } function IGRITEM() { $PO = $this->request->getPost('id'); $CreatedBy = $this->session->get('userId'); $this->inwardgateregister_model->UpdatePOMaster($PO, $CreatedBy); $data = $this->inwardgateregister_model->viewpurchaseorder($PO); echo json_encode($data); } function addloadfile() { $upfiles = ''; $pono = $this->request->getPost('PONO'); $igr = $this->request->getPost('igr'); $file = $this->request->getFile('file'); $requestfilename = $file->getName(); $files = $this->inwardgateregister_model->getfies($igr); $fcount = 0; foreach ($files as $value) { $lastfile = $value->FilePath;// not a file path just file name only if ($lastfile == $requestfilename) { $fcount++; } } if ($fcount == 0) { if (!empty($requestfilename)) { if ($file->isValid() && !$file->hasMoved()) { $file->move(ROOTPATH.'public/uploads/Igrfiles/'); $Picture = $file->getName(); }else{ $Picture = ""; } $myfiles = array('PONO' => $pono, 'IGRNO' => $igr, 'FilePath' => $Picture); $upfiles = $this->inwardgateregister_model->fileupload($myfiles); //print_r($upfiles); } } //echo 'filename'.$upfiles; if ($upfiles > 0) { echo "file updated successfully!"; } else { echo "File name already Exist"; } } function edituploadfile() { $bill = $this->request->getPost('param1'); $oldfile = $this->request->getPost('param2'); $newfile = $this->request->getFile('file'); if ($newfile->isValid() && !$newfile->hasMoved()) { $newfilename = $newfile->getName(); $newfile->move(ROOTPATH . 'public/uploads/Igrfiles/'); $Picture = str_replace(" ", "", $newfilename); } else { $Picture = $oldfile; } $uploadfile = $this->inwardgateregister_model->updatefile($bill, $Picture, $oldfile); // if($uploadfile > 0){ echo "updated successfully!"; // } // else{ // echo "updated successfully!"; // } } function addNewigr() { $PONO = $this->request->getPost('PONO'); $DeliveryChellanOrInvoiceNo = $this->request->getPost('InvoiceNo'); $DeliveryChellan = $this->request->getPost('InvoiceDate'); $DeliveryChellanDate = get_date_time_format($DeliveryChellan); $Mat_Rcvd_Dt = $this->request->getPost('MaterialRcvdDate'); $MaterialRcvdDt = get_date_time_format($Mat_Rcvd_Dt); $VehicleNo = $this->request->getPost('VehicleNo'); $CourierNo = $this->request->getPost('CourierNo'); $CreatedBy = $this->session->get('userId'); $RowCount = $this->request->getPost('txtRowCount'); $createddt = get_current_date_time(); $IGRStatus = IGR_CREATED; $document = null; $igr = array(); $paymentstatus = NO_PAIDIGR; $constant = $this->request->getPost('hideconstants'); $arr = []; $prefile = array(); $igr = array('PONO' => $PONO, 'VehicleNo' => $VehicleNo, 'DeliveryChellanOrInvoiceNo' => $DeliveryChellanOrInvoiceNo, 'DeliveryChellanDate' => $DeliveryChellanDate, 'MaterialRcvdDate' => $MaterialRcvdDt, 'CourierNo' => $CourierNo, 'IGRStatus' => $IGRStatus, 'CreatedBy' => $CreatedBy, 'CreatedDate' => $createddt, 'PaymentStatus' => $paymentstatus); $igrM = $this->inwardgateregister_model->addigrM($igr); $IGRNO = !empty($igrM) ? $igrM : ''; // $IGRNO = "IGRNO02695"; for ($i = 1; $i <= $constant; $i++) { $pathname = 'browseFiles' . $i; $file = $this->request->getFile($pathname); $requestfilename = $file->getName(); if (!empty($requestfilename)) { $files = str_replace(" ", "", $_FILES[$pathname]['name']); $fcount = 0; foreach ($prefile as $value) { if ($value == $files) { $fcount++; } } if ($fcount == 0) { if ($file->isValid() && !$file->hasMoved()) { $file->move(ROOTPATH.'public/uploads/Igrfiles/'); $Picture = $file->getName(); } $arr[] = array($Picture); } $prefile[] = $files; } } if (!empty($arr)) { foreach ($arr as $ma) { $index = 0; foreach ($ma as $key => $value) { $index++; if ($index == 1) { $filename = $value; } } if (!empty($filename)) { $myfile = array('FilePath' => $filename, 'PONO' => $PONO, 'IGRNO' => $IGRNO); $this->inwardgateregister_model->fileupload($myfile); } } } $OGRStatus = IGR_CREATED; $check_OGRPO = $this->inwardgateregister_model->update_OGR($PONO, $OGRStatus); $IGRItemStatus = REQITEM_NEW; $TotalPendingQty = ''; $TotalPendingQty = (int)$TotalPendingQty; for ($i = 1; $i <= $RowCount; $i++) { $MaterialCode = $this->request->getPost('MaterialCode' . $i); $MaterialCode = $MaterialCode !== null && is_string($MaterialCode) ? trim($MaterialCode) : null; $QuantityAsPerInvoice = $this->request->getPost('txtQuantityAsPerInvoice' . $i); $QuantityAsPerInvoice = $QuantityAsPerInvoice !== null && is_string($QuantityAsPerInvoice) ? trim($QuantityAsPerInvoice) : null; $OrderedQuantity = $this->request->getPost('OrderedQuantity' . $i); $OrderedQuantity = $OrderedQuantity !== null && is_string($OrderedQuantity) ? trim($OrderedQuantity) : null; $ReceivedQty = $this->request->getPost('txtReceivedQuantity' . $i); $ReceivedQty = $ReceivedQty !== null && is_string($ReceivedQty) ? trim($ReceivedQty) : null; $PendingQty = $this->request->getPost('txtPendingQty' . $i); $TotalPendingQty = $TotalPendingQty + $PendingQty; if (strlen($QuantityAsPerInvoice) > 0 && $QuantityAsPerInvoice != '0') { $Remarks = $this->request->getPost('txtRemarks' . $i); $ItemStatus = ''; if ($PendingQty == 0.00) { $ItemStatus = IGR_CREATED; } else { $ItemStatus = POLINEITEM_IGRPARTIAL_CREATED; } $CreatedBy = $this->session->get('userId'); $igrDetails = array('IGRNO' => $IGRNO, 'MaterialCode' => $MaterialCode, 'QuantityAsPerInvoice' => $QuantityAsPerInvoice, 'Remarks' => $Remarks, 'IGRItemStatus' => $IGRItemStatus, 'CreatedBy' => $CreatedBy, 'CreatedDate' => $createddt); $igrD = $this->inwardgateregister_model->addigrD($igrDetails); $igrlineno = !empty($igrD) ? $igrD : ''; $itemvalue = ''; $SupplierId = ''; $polineitemvalue = $this->inwardgateregister_model->getitemvalue($PONO, $MaterialCode); foreach ($polineitemvalue as $it) { $itemvalue = $it->Rate; $SupplierId = $it->SupplierID; } $historydetails = array('MaterialCode' => $MaterialCode, 'Transaction_type' => "Add", 'Ref_Type' => "IGR", 'Ref_No' => $igrlineno, 'Quantity' => $QuantityAsPerInvoice, 'CreatedBy' => $CreatedBy, 'CreatedOn' => $createddt, 'SupplierID' => $SupplierId, 'ItemValue' => $itemvalue); $this->inwardgateregister_model->addmaterialhistory($historydetails); $get_pre_qty = $this->inwardgateregister_model->get_CurrentQty($MaterialCode); $av_qty = 0; if (!empty($get_pre_qty)) { foreach ($get_pre_qty as $gt) { $av_qty = $gt->Current_stock; } } $currentav_qty = $QuantityAsPerInvoice + $av_qty; $current_qty = array('Current_stock' => $currentav_qty); $this->inwardgateregister_model->addmaterialmaster($current_qty, $MaterialCode); $Recqty = $this->inwardgateregister_model->getPOLineItemReceivedQty($PONO, $MaterialCode); $ReceivedQuantity = 0.00; if (count($Recqty) > 0) { foreach ($Recqty as $key) { $ReceivedQuantity = $key->ReceivedQuantity; } } $totalReceivedqty = $ReceivedQuantity + $QuantityAsPerInvoice; $POLineItem = array('ReceivedQuantity' => $totalReceivedqty, 'Status' => $ItemStatus, 'UpdateBY' => $CreatedBy, 'UpdatedOn' => $createddt); $this->inwardgateregister_model->UpdatePOLineItem($POLineItem, $PONO, $MaterialCode); } } $this->inwardgateregister_model->UpdatePOMaster($PONO, $CreatedBy); if ($TotalPendingQty == 0.00) { $Newstatus = array('Status' => IGR_CREATED); $this->inwardgateregister_model->POLineItemsupdatestatus($PONO, $Newstatus); $this->inwardgateregister_model->pomasterupdatestatus($PONO, $Newstatus); } else { /*echo 'error' ;*/ } echo ""; } function ViewIGR() { $IGRNO = $this->request->getPost('id'); $data = $this->inwardgateregister_model->viewigr($IGRNO); // print_r( $data);die; echo json_encode($data); } function ViewIGRfile() { $IGRNO = $this->request->getPost('id'); $igrfile = $this->inwardgateregister_model->viewIGRFile($IGRNO); $billfile = $this->inwardgateregister_model->ViewIGRfile1($IGRNO); $data = array_merge($igrfile, $billfile); echo json_encode($data); } function UpdateIGR() { $IGRNo = $this->request->getPost('igr'); $DeliveryChellan = $this->request->getPost('invdate'); $DeliveryChellanDate = get_date_time_format($DeliveryChellan); $Mat_Rcvd_Dt = $this->request->getPost('mrc'); $MaterialRcvdDt = get_date_time_format($Mat_Rcvd_Dt); $updateby = $this->session->get('userId'); $updatedon = get_date_time_format('Y-m-d H:i:s'); $igrarr = array('DeliveryChellanDate' => $DeliveryChellanDate, 'MaterialRcvdDate' => $MaterialRcvdDt, 'UpdateBY' => $updateby, 'UpdatedOn' => $updatedon); $data = $this->inwardgateregister_model->updateigr($igrarr, $IGRNo); if ($data > 0) { echo "Updated Succefully!"; } else { echo "Not Updated!"; } } function AddOgr() { //echo "string"; $type = $this->request->getPost('type'); $Supplier = $this->request->getPost('sup'); $Date = $this->request->getPost('Date'); $vehicle = $this->request->getPost('Vehicle'); $driver = $this->request->getPost('drive'); if ($type == 1) { $invoice = $this->request->getPost('invno'); $Otype = 'Invoice'; $Status = 'ST063'; $ogrmaster = array( 'OgrType' => $Otype, 'CreatedDate' => $Date, 'Driver' => $driver, 'PONO_INV' => $invoice, 'VehicleNo' => $vehicle, 'Status' => $Status ); $addogrmaster = $this->inwardgateregister_model->AddOGR($ogrmaster); $OGRNO = ''; if (count($addogrmaster) > 0) { foreach ($addogrmaster as $add) { $OGRNO = $add->OGRNO; } } $itemcode = $this->request->getPost('itemcode'); $Description = $this->request->getPost('Description'); $invoutwardqty = $this->request->getPost('invoutwardqty'); $Ogrline = array('OGRNO' => $OGRNO, 'MaterialCode' => $itemcode, 'OutwardQty' => $invoutwardqty, 'Status' => $Status); $addOgrline = $this->inwardgateregister_model->AddOgrLine($Ogrline); if ((count($addogrmaster) > 0) && (count($addOgrlines > 0))) { echo "Saved Successfully OGR No is OGR" . $OGRNO; } } else if ($type == 2) { $pono = $this->request->getPost('pono'); $MRIRNO = $this->request->getPost('mrirno'); $Otype = 'PO'; $row = $this->request->getPost('rowcount'); $ogrmaster = array( 'OgrType' => $Otype, 'CreatedDate' => $Date, 'Driver' => $driver, 'PONO_INV' => $pono, 'VehicleNo' => $vehicle, 'MRIRNO' => $MRIRNO ); $addogrmaster = $this->inwardgateregister_model->AddOGR($ogrmaster); $OGRNO = ''; if (count($addogrmaster) > 0) { foreach ($addogrmaster as $add) { $OGRNO = $add->OGRNO; } } for ($i = 1; $i <= $row; $i++) { $MaterialCode = $this->request->getPost('materialcode' . $i); $OutwardQty = $this->request->getPost('outward' . $i); $rejqty = $this->request->getPost('RejectedQty' . $i); $pendingoutward = $this->request->getPost('pendingoutward' . $i); $balance_Qty = $rejqty - $OutwardQty; //$balance_Qty = $this->request->getPost('pendingoutward'.$i); $Outwardtotal = $OutwardQty; $allowed = $this->request->getPost('allowed' . $i); if ($MaterialCode != '' && $OutwardQty != '') { $polqty = $this->inwardgateregister_model->getPOLineItemReceivedQty($pono, $MaterialCode); $ReceivedQuantity = 0.00; if (count($polqty) > 0) { foreach ($polqty as $key) { $ReceivedQuantity = $key->ReceivedQuantity; } } $totalReceivedqty = $ReceivedQuantity - $Outwardtotal; $POMStatus = OGR_CREATED; $POLineItem = array('ReceivedQuantity' => $totalReceivedqty, 'OGR_Status' => $POMStatus); $this->inwardgateregister_model->UpdatePOLineItem($POLineItem, $pono, $MaterialCode); if ($pendingoutward == 0) { $Status = OGR_COMPLETE; } else { $Status = OGR_PARTIAL_COMPLETE; } $Ogrline = array('OGRNO' => $OGRNO, 'MaterialCode' => $MaterialCode, 'OutwardQty' => $Outwardtotal, 'Status' => $Status, 'balance_Qty' => $balance_Qty); $addOgrline = $this->inwardgateregister_model->AddOgrLine($Ogrline); //print_r($addOgrline); $ogrlineno = ''; $itemvalue = ''; $SupplierId = ''; $CreatedBy = $this->session->get('userId'); $createddt = get_current_date_time(); if (count($addogrmaster) > 0) { $ogrlinearray = $this->inwardgateregister_model->getlastogrline(); foreach ($ogrlinearray as $og) { $ogrlineno = $og->OGRItemNO; } $polineitemvalue = $this->inwardgateregister_model->getitemvalue($pono, $MaterialCode); foreach ($polineitemvalue as $it) { $itemvalue = $it->Rate; $SupplierId = $it->SupplierID; } } $historydetails = array('MaterialCode' => $MaterialCode, 'Transaction_type' => "Reduce", 'Ref_Type' => "OGR", 'Ref_No' => $ogrlineno, 'Quantity' => $Outwardtotal, 'CreatedBy' => $CreatedBy, 'CreatedOn' => $createddt, 'ItemValue' => $itemvalue, 'SupplierID' => $SupplierId); $this->inwardgateregister_model->addmaterialhistory($historydetails); $get_pre_qty = $this->inwardgateregister_model->get_CurrentQty($MaterialCode); $av_qty = 0; if (!empty($get_pre_qty)) { foreach ($get_pre_qty as $gt) { $av_qty = $gt->Current_stock; } } $currentav_qty = $av_qty - $Outwardtotal; $current_qty = array('Current_stock' => $currentav_qty); $this->inwardgateregister_model->addmaterialmaster($current_qty, $MaterialCode); $this->inwardgateregister_model->UpdateOGRMasterOGRStatus($OGRNO); $this->inwardgateregister_model->UpdateMRIRMasterOGRStatus($MRIRNO, $OGRNO); $mrirout = $this->inwardgateregister_model->GetMRIROutQty($MRIRNO, $MaterialCode); $premrirout = 0; if (!empty($mrirout)) { foreach ($mrirout as $mr) { $premrirout = $mr->Ogr_Out_Qty; } } $totmrirout = $premrirout + $Outwardtotal; $mrirarray = array('Ogr_Out_Qty' => $totmrirout); $this->inwardgateregister_model->UpdateMRIROUTQty($mrirarray, $MRIRNO, $MaterialCode); $POMasterStatus = array('Status' => PO_RELEASED); $this->inwardgateregister_model->UpdatePOMasterOGRStatus($pono, $POMasterStatus); } } if ((count($addogrmaster) > 0) && (count($addOgrline) > 0)) { echo "Saved Successfully OGR No is OGR" . $OGRNO; } } else if ($type == 3) { $Otype = 'SERVICE'; $Status = 'ST063'; $ogrmaster = array('OgrType' => $Otype, 'CreatedDate' => $Date, 'Driver' => $driver, 'VehicleNo' => $vehicle, 'Status' => $Status); $addogrmaster = $this->inwardgateregister_model->AddOGR($ogrmaster); //print_r($addogrmaster); $OGRNO = ''; //echo count($addogrmaster); if (count($addogrmaster) > 0) { foreach ($addogrmaster as $add) { $OGRNO = $add->OGRNO; } } $material = $this->request->getPost('material'); $name = $this->request->getPost('name'); $pooutward = $this->request->getPost('pooutward'); $destination = $this->request->getPost('destination'); $Remarks = $this->request->getPost('Remark'); $Ogrline = array('OGRNO' => $OGRNO, 'MaterialCode' => $material, 'OutwardQty' => $pooutward, 'Destination' => $destination, 'Status' => $Status, 'SupplierID' => $name, 'Remark' => $Remarks); //print_r($Ogrline); //die(); $addOgrline = $this->inwardgateregister_model->AddOgrLine($Ogrline); if ((count($addogrmaster) > 0) && (count($addOgrline > 0))) { echo "Saved Successfully OGR No is OGR" . $OGRNO; } } } }