diff --git a/.env b/.env deleted file mode 100755 index 08c6572b..00000000 --- a/.env +++ /dev/null @@ -1,74 +0,0 @@ -#-------------------------------------------------------------------- -# Example Environment Configuration file -# -# This file can be used as a starting point for your own -# custom .env files, and contains most of the possible settings -# available in a default install. -# -# By default, all of the settings are commented out. If you want -# to override the setting, you must un-comment it by removing the '#' -# at the beginning of the line. -#-------------------------------------------------------------------- - -#-------------------------------------------------------------------- -# ENVIRONMENT -#-------------------------------------------------------------------- - -CI_ENVIRONMENT = development - -#-------------------------------------------------------------------- -# APP -#-------------------------------------------------------------------- - -app.baseURL = 'http://localhost/ria/' -# If you have trouble with `.`, you could also use `_`. -# app_baseURL = '' -# app.forceGlobalSecureRequests = false -# app.CSPEnabled = false - -#-------------------------------------------------------------------- -# DATABASE -#-------------------------------------------------------------------- -# database.default.hostname = 'vprodb1.mysql.database.azure.com' -# database.default.database = 'ria_prod' -# database.default.username = 'dbroot' -# database.default.password = 'root@DB23' - -database.default.hostname = '119.18.54.85' -database.default.database = 'venbaehn_ria' -database.default.username = 'venbaehn_ria' -database.default.password = 'Q{c2b{7mIC^$' -database.default.DBDriver = MySQLi -database.default.DBPrefix = -database.default.port = 3306 - - -# If you use MySQLi as tests, first update the values of Config\Database::$tests. -# database.tests.hostname = localhost -# database.tests.database = ci4_test -# database.tests.username = root -# database.tests.password = root -# database.tests.DBDriver = MySQLi -# database.tests.DBPrefix = -# database.tests.charset = utf8mb4 -# database.tests.DBCollat = utf8mb4_general_ci -# database.tests.port = 3306 - -#-------------------------------------------------------------------- -# ENCRYPTION -#-------------------------------------------------------------------- - -# encryption.key = - -#-------------------------------------------------------------------- -# SESSION -#-------------------------------------------------------------------- - -# session.driver = 'CodeIgniter\Session\Handlers\FileHandler' -# session.savePath = null - -#-------------------------------------------------------------------- -# LOGGER -#-------------------------------------------------------------------- - -# logger.threshold = 4 diff --git a/.gitignore b/.gitignore index 74198609..988eadc6 100755 --- a/.gitignore +++ b/.gitignore @@ -98,6 +98,15 @@ public/uploads/Igrfiles/* public/uploads/images/* !public/uploads/images/index.html +public/uploads/POfiles/* +!public/uploads/POfiles/.gitkeep + +public/assets/images/emp_files/* +!public/assets/images/emp_files/.gitkeep + +public/assets/images/invoice_files/* +!public/assets/images/invoice_files/.gitkeep + php_errors.log /app/Views/*.tmp diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 1c314c49..310a4c2b 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -263,6 +263,11 @@ $routes->post('inwardgateregister/edituploadfile', 'Inwardgateregister::edituplo $routes->match(['GET', 'POST', 'PUT', 'DELETE'],'AddOgr', 'Inwardgateregister::addoutwardgateregister'); $routes->match(['GET', 'POST', 'PUT', 'DELETE'],'ViewOgr', 'Inwardgateregister::ViewOgr'); $routes->match(['GET', 'POST', 'PUT', 'DELETE'],'EditOGR', 'Inwardgateregister::EditOGR'); +$routes->get('drivernameautocomplete' , 'Inwardgateregister::drivernameautocomplete'); +$routes->get('drivermobileautocomplete', 'Inwardgateregister::drivermobileautocomplete'); + + + // Application MRIR Routes $routes->match(['GET', 'POST', 'PUT', 'DELETE'],'EditMRIR', 'MRIRcontroller::editmaterialinspectionreport'); @@ -352,3 +357,12 @@ $routes->get('qualityreportlistinward', 'Quality::reportListInward'); $routes->get('shortagematerialListing', 'Rawmaterialdetails::shortagematerialListing'); $routes->get('inprocess', 'Inprocess::index'); + + +// Sales Controller +$routes->get('sales_dashboard', 'Sales::sales_dashboard'); +$routes->get('invoicedetails/ViewInvoice', 'Sales::ViewInvoice'); +$routes->get('getInvoiceAttachments', 'Sales::getInvoiceAttachments'); +$routes->get('deleteAttachment', 'Sales::deleteAttachment'); +$routes->post('saveAttachment', 'Sales::saveAttachment'); +$routes->get('sales_invoice', 'Sales::sales_invoice'); diff --git a/app/Controllers/Inwardgateregister.php b/app/Controllers/Inwardgateregister.php index a82917df..46a98778 100755 --- a/app/Controllers/Inwardgateregister.php +++ b/app/Controllers/Inwardgateregister.php @@ -311,7 +311,6 @@ class Inwardgateregister extends BaseController function SaveIGR() { - //print_r($this->request->getPost());die; #Step 1 IGR Details $PONO = $this->request->getPost('PONO'); $IsThisOpenOrderPO = $this->request->getPost('hiddenIsOpenOrder'); @@ -321,6 +320,7 @@ class Inwardgateregister extends BaseController $Mat_Rcvd_Dt = (string)$this->request->getPost('MaterialRcvdDate'); $MaterialRcvdDt = get_date_time_format($Mat_Rcvd_Dt); $VehicleNo = $this->request->getPost('VehicleNo'); + $VehicleType = $this->request->getPost('VehicleType'); $DriverName = $this->request->getPost('DriverName'); $DriverMobileNumber = $this->request->getPost('DriverMobileNumber'); $CreatedBy = $this->session->get('userId'); @@ -355,16 +355,14 @@ class Inwardgateregister extends BaseController } } } - #Step 3 Master Details Gathering to Save In DB - $igr = array('PONO' => $PONO, 'VehicleNo' => $VehicleNo, 'DeliveryChellanOrInvoiceNo' => $DeliveryChellanOrInvoiceNo, 'DeliveryChellanDate' => $DeliveryChellanDate, 'MaterialRcvdDate' => $MaterialRcvdDt, 'DriverName' => $DriverName, 'DriverMobileNumber' => $DriverMobileNumber,'IGRStatus' => $IGRStatus, 'CreatedBy' => $CreatedBy, 'CreatedDate' => $createddt, 'PaymentStatus' => $paymentstatus); + $igr = array('PONO' => $PONO, 'VehicleNo' => $VehicleNo, 'VehicleType'=>$VehicleType,'DeliveryChellanOrInvoiceNo' => $DeliveryChellanOrInvoiceNo, 'DeliveryChellanDate' => $DeliveryChellanDate, 'MaterialRcvdDate' => $MaterialRcvdDt, 'DriverName' => $DriverName, 'DriverMobileNumber' => $DriverMobileNumber,'IGRStatus' => $IGRStatus, 'CreatedBy' => $CreatedBy, 'CreatedDate' => $createddt, 'PaymentStatus' => $paymentstatus); $igr['MasterFile'] = $requestMasterFileName; - // print_r( $igr );die; #Step 4 Calling DB to Save IGR Master $IGRNO = $this->inwardgateregister_model->addigrM($igr); - // Get the uploaded files - // $IGRNO = "IGRNO02750"; - // $IGRNO = "IGRNO02734"; + // echo "master - no problem"; + // $IGRNO = "IGRNO02767"; + // print_r($this->request->getPost());die; if($IGRNO){ $files = $this->request->getFiles(); $fileNames = $this->request->getPost('file_name'); // Get user-entered file names @@ -461,20 +459,25 @@ class Inwardgateregister extends BaseController $GrossWeightDate = !empty($grossWeightDate) && is_string($grossWeightDate) ? date('Y-m-d H:i:s', strtotime($grossWeightDate)) : null; $TareWeightDate = !empty($tareWeightDate) && is_string($tareWeightDate) ? date('Y-m-d H:i:s', strtotime($tareWeightDate)) : null; log_message('error', "TareWeightDate" . $TareWeightDate); - if (strlen($QuantityAsPerInvoice) > 0 && $QuantityAsPerInvoice != '0') { $Remarks = $this->request->getPost('txtRemarks' . $i); $ItemStatus = ''; - if ($PendingQty == 0.00) { - $ItemStatus = $IGRStatus; - } else { + if (strlen($QuantityAsPerInvoice) > 0 && $QuantityAsPerInvoice != '0') { + if ($PendingQty == 0.00) { + $ItemStatus = $IGRStatus; + } else { + $ItemStatus = POLINEITEM_IGRPARTIAL_CREATED; + } + } + else if ((int)$IsThisOpenOrderPO == 1) { $ItemStatus = POLINEITEM_IGRPARTIAL_CREATED; } $CreatedBy = $this->session->get('userId'); $igrDetails = array('IGRNO' => $IGRNO, 'MaterialCode' => $MaterialCode, 'QuantityAsPerInvoice' => $QuantityAsPerInvoice, 'Remarks' => $Remarks, 'IGRItemStatus' => $IGRItemStatus,'GrossWeight' => (float)$GrossWeight ,'GrossWeightDate'=> $GrossWeightDate,'TareWeight' => (float)$TareWeight ,'TareWeightDate' => $TareWeightDate ,'NetWeight' => (float)$NetWeight, 'CreatedBy' => $CreatedBy, 'CreatedDate' => $createddt); $igrDetails['WeightFile'] = $requestWeightFileName; + log_message('error', 'SaveIGR igrDetails result : ' . json_encode($igrDetails)); - + $igrlineno = ""; $igrD = $this->inwardgateregister_model->addigrD($igrDetails); $igrlineno = !empty($igrD) ? $igrD : ''; @@ -527,7 +530,7 @@ class Inwardgateregister extends BaseController log_message('error', "History updated successfully. History id: " . $history_id); } $get_pre_qty = $this->inwardgateregister_model->get_CurrentQty($MaterialCode); - $av_qty = 0; + $av_qty = 0; //$av_qty means Avaliable Quantity if (!empty($get_pre_qty)) { foreach ($get_pre_qty as $gt) { $av_qty = $gt->Current_stock; @@ -543,49 +546,11 @@ class Inwardgateregister extends BaseController $ReceivedQuantity = $key->ReceivedQuantity; } } - $totalReceivedqty = $ReceivedQuantity + $QuantityAsPerInvoice; + $totalReceivedqty = (int)$IsThisOpenOrderPO == 1 ? 0 : $ReceivedQuantity + $QuantityAsPerInvoice ; + // $totalReceivedqty = $ReceivedQuantity + $QuantityAsPerInvoice; $POLineItem = array('ReceivedQuantity' => $totalReceivedqty, 'Status' => $ItemStatus, 'UpdateBY' => $CreatedBy, 'UpdatedOn' => $createddt); $this->inwardgateregister_model->UpdatePOLineItem($POLineItem, $PONO, $MaterialCode); - } - else if ((int)$IsThisOpenOrderPO == 1) { - $ItemStatus = POLINEITEM_IGRPARTIAL_CREATED; - - # Is this open order po means i have to save IGR DETAILS - $Remarks = $this->request->getPost('txtRemarks' . $i); - $ItemStatus = POLINEITEM_IGRPARTIAL_CREATED; - $CreatedBy = $this->session->get('userId'); - $igrDetails = array('IGRNO' => $IGRNO, 'MaterialCode' => $MaterialCode, 'QuantityAsPerInvoice' => $QuantityAsPerInvoice, 'Remarks' => $Remarks, 'IGRItemStatus' => $IGRItemStatus,'GrossWeight' => (float)$GrossWeight ,'GrossWeightDate'=> $GrossWeightDate,'TareWeight' => (float)$TareWeight ,'TareWeightDate' => $TareWeightDate ,'NetWeight' => (float)$NetWeight, 'CreatedBy' => $CreatedBy, 'CreatedDate' => $createddt); - $igrDetails['WeightFile'] = $requestWeightFileName; - $igrD = $this->inwardgateregister_model->addigrD($igrDetails); - $igrD =''; - $igrlineno = !empty($igrD) ? $igrD : ''; - log_message('error', 'SaveIGR igrDetails result : ' . json_encode($igrDetails)." IgrLineNo : ".$igrlineno); - $itemvalue = ''; - $SupplierId = ''; - $polineitemvalue = $this->inwardgateregister_model->getitemvalue($PONO, $MaterialCode); - foreach ($polineitemvalue as $it) { - $itemvalue = $it->Rate; - $SupplierId = $it->SupplierID; - } - # Is this open order po means i have to save add material history - $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); - - # Is this open order po means i have to save the get received qty in PO lineitem table - $get_pre_qty = $this->inwardgateregister_model->get_CurrentQty($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,$IGRStatus); #Step 9 Updating Pending Quantity IN PO Master amd Line Item Details. @@ -619,8 +584,38 @@ class Inwardgateregister extends BaseController "; } +function drivernameautocomplete(){ + $dr = $this->request->getGet('query'); + $query = $this->inwardgateregister_model->checkdrivername($dr); + echo json_encode($query); +} +public function drivermobileautocomplete() { + $dr = $this->request->getGet('query'); + $drName = $this->request->getGet('driverName'); + $query = $this->inwardgateregister_model->checkdriverMobile($dr, $drName); + echo json_encode($query); +} +public function drivermobileautocomplete2() { + $driverName = $this->request->getGet('drivername'); + $term = $this->request->getGet('term'); + + // Debugging + if (!$driverName || !$term) { + return $this->response->setJSON(['error' => 'Missing parameters']); + } + + $query = $this->inwardgateregister_model->checkdriverMobile($driverName, $term); + + // Check the output + if (is_array($query)) { + return $this->response->setJSON($query); + } else { + return $this->response->setJSON(['error' => 'Invalid response from model']); + } +} + function viewIGRDetails() { @@ -671,6 +666,7 @@ function viewIGRDetails() $VehicleNo = $this->request->getPost('vehicle_no'); + $VehicleType = $this->request->getPost('vehicle_type'); $DriverName = $this->request->getPost('driver'); $DriverMobileNumber = $this->request->getPost('driver_mobile'); @@ -685,7 +681,7 @@ function viewIGRDetails() $path = ROOTPATH.'public/uploads/Igrfiles/'; if(!is_dir($path)) { mkdir($path, 0777, true); } - $igrarr = array('DeliveryChellanDate' => $DeliveryChellanDate, 'MaterialRcvdDate' => $MaterialRcvdDt,'VehicleNo'=>$VehicleNo,'DriverMobileNumber'=>$DriverMobileNumber,'DriverName'=>$DriverName, 'IGRStatus' => $IGRStatus,'UpdateBY' => $updateby); + $igrarr = array('DeliveryChellanDate' => $DeliveryChellanDate, 'MaterialRcvdDate' => $MaterialRcvdDt,'VehicleNo'=>$VehicleNo,'VehicleType'=>$VehicleType,'DriverMobileNumber'=>$DriverMobileNumber,'DriverName'=>$DriverName, 'IGRStatus' => $IGRStatus,'UpdateBY' => $updateby); $MasterFile = $this->request->getfile('MasterFile'); diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php new file mode 100644 index 00000000..f35fea79 --- /dev/null +++ b/app/Controllers/Sales.php @@ -0,0 +1,127 @@ +ipinvoice_model = new Ipinvoice_model(); + $this->session = session(); + $this->isLoggedIn(); + } + + public function sales_dashboard() + { + $this->global['pageTitle'] = 'Sales Dashboard'; + $data = []; + $data['today_sales'] = $this->ipinvoice_model->todaySales(); + $data['this_month_sales'] = $this->ipinvoice_model->thisMonthSales(); + $data['this_year_sales'] = $this->ipinvoice_model->thisYearSales(); + $data['this_year_sales_trend'] = $this->ipinvoice_model->thisYearSalesTrend(); + $data['get_today_invoices'] = $this->ipinvoice_model->getTodayInvoices(); + echo "
";
+        print_r($data);die;
+        $this->loadViews("sales_dashboard", $this->global, $data, NULL);
+    }
+
+    //  Sales Invoice List 
+    function sales_invoice(){
+        $this->global['pageTitle'] = 'Sales Invoice';
+        $data['sales_invoice'] = $this->ipinvoice_model->saleInvoiceListing();
+        // echo "
";
+        // print_r($data);die;
+        $this->loadViews("sales_invoice", $this->global, $data, NULL);
+    }
+    
+    // View Invoice 
+    function ViewInvoice($InvoiceNO = '')
+    {
+        if ($InvoiceNO == '') {
+            $InvoiceID =  $_GET['InvoiceID'];
+        } else {
+                    $InvoiceID  = $InvoiceNO;
+        }
+        
+        $data['invoiceDetails'] = $this->ipinvoice_model->getInvoice($InvoiceID);
+
+        $data['invoiceAttachment'] = $this->ipinvoice_model->getinvoiceAttachment($InvoiceID);
+        
+        //   echo "
";
+        //   print_r($data);die;
+        $this->global['pageTitle'] = 'View Invoice';
+        
+        $this->loadViews("editInvoice", $this->global,  $data, NULL);
+    }
+    
+    
+    // Invoice Attachments 
+    function getInvoiceAttachments(){
+            $data['invoiceAttachment'] = $this->ipinvoice_model->getinvoiceAttachment($this->request->getGet('invoice_id'));
+
+            return json_encode($data);
+    }
+    
+    
+    // Delete Attachment
+    function deleteAttachment() 
+    {
+        $invoice_attachment_id = $this->request->getGet('invoice_attachment_id'); // Get the attachment ID from the request
+        // Ensure ID is not empty
+        if ($invoice_attachment_id) {
+            // Load the model
+
+            // Call the model method to delete the attachment
+            $result = $this->ipinvoice_model->deleteAttachment($invoice_attachment_id);
+
+            if ($result) {
+                echo json_encode(['status' => 'success', 'message' => 'Attachment deleted successfully.']);
+            } else {
+                echo json_encode(['status' => 'error', 'message' => 'Failed to delete attachment.']);
+            }
+        } else {
+            echo json_encode(['status' => 'error', 'message' => 'Invalid attachment ID.']);
+        }
+    }
+    
+    // Save Attachment
+    function saveAttachment() {
+        $invoiceId = $this->request->getPost('invoice_id');
+        $fileNames = $this->request->getPost('file_name[]');
+        $files = $this->request->getFiles();
+        if ($files && isset($files['emp_file']) && is_array($files['emp_file'])) {
+            foreach ($files['emp_file'] as $key => $file) {
+                if ($file->isValid() && !$file->hasMoved()) {
+                    // Generate a unique name for the file
+                    $newFileName = $file->getRandomName();
+    
+                    // Move the file to the target directory
+                    $file->move('./public/uploads/images/invoice_files/', $newFileName);
+    
+                    // Insert the file info into the database
+                    $data = [
+                        'invoice_id' => $invoiceId,
+                        'file_name' => $newFileName,
+                        'attachment_name' => $fileNames[$key]
+                    ];
+    
+                    $this->ipattachment_model->addNewAttachment($data);
+                }
+            }
+        } else {
+            return $this->response->setJSON(['success' => false, 'message' => 'No files uploaded or incorrect input name.']);
+        }
+    
+        return $this->response->setJSON(['success' => true]);
+    }
+}
\ No newline at end of file
diff --git a/app/Controllers/User.php b/app/Controllers/User.php
index 7e2e694b..6eb84fa6 100644
--- a/app/Controllers/User.php
+++ b/app/Controllers/User.php
@@ -10,6 +10,8 @@ use App\Models\Costcenter_model;
 use App\Models\Dashboard_model;
 use App\Models\Employeedetails_model;
 use App\Models\User_model;
+use App\Models\Ipinvoice_model;
+use App\Models\Ipattachment_model;
 use App\Models\Zohobooks_api_model;
 require_once 'vendor/autoload.php';
 
@@ -27,6 +29,8 @@ class User extends BaseController
     protected  $dahsboard_Model;
     protected  $employeedetails_model;
     protected  $user_model;
+    protected  $ipinvoice_model;
+    protected  $ipattachment_model;
     protected $session;
 
     /**
@@ -40,6 +44,8 @@ class User extends BaseController
         $this->costcenter_model = new Costcenter_model();
         $this->employeedetails_model = new employeedetails_model();
         $this->user_model = new User_model();
+        $this->ipinvoice_model = new Ipinvoice_model();
+        $this->ipattachment_model = new Ipattachment_model();
         $this->session = session();
         helper('form'); //$this->load->library('form_validation');
         $this->isLoggedIn();
@@ -1274,355 +1280,361 @@ class User extends BaseController
         //  print_r($_GET);
         // echo isset($_GET['from']) ? $_GET['from'] : 'n';
         // echo isset($_GET['to']) ? $_GET['to'] : 'n';
-                // die();
-                try{
-                    // if (isset($_POST['sync']) || $_GET['from'] != null && $_GET['to'] != null) 
-                    // {
-                        // $ch=curl_init();
-                        //$this->load->helper('zohobooks_fetch_api_helper');
-                        helper('zohobook');
-                        $Zohobook_model = model('Zohobook_api_model');
-                        if(isset($_GET['from']) && $_GET['from'] != null && isset($_GET['to']) && $_GET['to'] != null)
-                        {
-                          $date_today = $_GET['to'];
-                          $date_yesterday = $_GET['from'];
+        // die();
+        try{
+            // if (isset($_POST['sync']) || $_GET['from'] != null && $_GET['to'] != null) 
+            // {
+                // $ch=curl_init();
+                //$this->load->helper('zohobooks_fetch_api_helper');
+                helper('zohobook');
+                $Zohobook_model = model('Zohobook_api_model');
+                if(isset($_GET['from']) && $_GET['from'] != null && isset($_GET['to']) && $_GET['to'] != null)
+                {
+                    $date_today = $_GET['to'];
+                    $date_yesterday = $_GET['from'];
+                }
+                else
+                {
+                    $date_today = date('Y-m-d');
+                    $date_yesterday = date('Y-m-d',strtotime('-3 day',strtotime($date_today)));
+                }
+                // echo $date_today.'--'.$date_yesterday;die;
+                $chk_acc_token_val = $Zohobook_model->get_data('zohobook_accesstoken','id' , 1);
+                // print_r($chk_acc_token_val);//die();
+                $date = new \DateTime($chk_acc_token_val[0]['created_at']); 
+                //print_r($date);
+                $date->add(new \DateInterval('PT1H'));
+                //print_r($date);
+                //echo '****************';
+                //print_r(date('Y-m-d h:i:s'));
+                $token = 0;
+                if ($date->format('Y-m-d H:i:s') > date('Y-m-d H:i:s')) {  $token = $chk_acc_token_val[0]['token']; } 
+                else { $token = generateNewToken(); $tokendata['token'] = $token; $Zohobook_model->customUpdate($tokendata , 1,'zohobook_accesstoken'); }
+                    // $token = generateNewToken(); $tokendata['token'] = $token; 
+                    //$Zohobook_model->update($tokendata , 1,'zohobook_accesstoken');  
+                    $result = getheringInvoiceDetails($date_today , $date_yesterday , $token);
+                    $headers_new = $result['headers_new'];
+                    $res = json_decode($result['data'],true);
+                    $inv_array = $res['invoices'];
+                    // print_r($inv_array);
+                    // echo "rrrr";
+                    // die();
+                    foreach($inv_array as $inv){
+                        $invoice_id = $inv['invoice_id'];
+                        //filter only einvoice status pushed invoices only
+                        //&& isset($inv['einvoice_details']) && isset($inv['einvoice_details']['status']) && ($inv['einvoice_details']['status'] == 'pushed')
+                        if($invoice_id !== "" ){
+                            $organization_id = '776847408';
+                            $result2=getheringInvoiceSubDetails($invoice_id,$organization_id,$headers_new);
+                            $resall = json_decode($result2,true);
+                            $res2[] = $resall['invoice'];
                         }
-                        else
-                        {
-                          $date_today = date('Y-m-d');
-                          $date_yesterday = date('Y-m-d',strtotime('-3 day',strtotime($date_today)));
-                        }
-                        // echo $date_today.'--'.$date_yesterday;die;
-                        $chk_acc_token_val = $Zohobook_model->get_data('zohobook_accesstoken','id' , 1);
-                       // print_r($chk_acc_token_val);//die();
-                        $date = new \DateTime($chk_acc_token_val[0]['created_at']); 
-                        //print_r($date);
-                        $date->add(new \DateInterval('PT1H'));
-                        //print_r($date);
-                        //echo '****************';
-                        //print_r(date('Y-m-d h:i:s'));
-                        $token = 0;
-                        if ($date->format('Y-m-d H:i:s') > date('Y-m-d H:i:s')) {  $token = $chk_acc_token_val[0]['token']; } 
-                        else { $token = generateNewToken(); $tokendata['token'] = $token; $Zohobook_model->customUpdate($tokendata , 1,'zohobook_accesstoken'); }
-                       // $token = generateNewToken(); $tokendata['token'] = $token; 
-                        //$Zohobook_model->update($tokendata , 1,'zohobook_accesstoken');  
-                          $result = getheringInvoiceDetails($date_today , $date_yesterday , $token);
-                            $headers_new = $result['headers_new'];
-                            $res = json_decode($result['data'],true);
-                            $inv_array = $res['invoices'];
-                            // print_r($inv_array);
-                            // echo "rrrr";
-                            // die();
-                            foreach($inv_array as $inv){
-                                $invoice_id = $inv['invoice_id'];
-                                //filter only einvoice status pushed invoices only
-                                //&& isset($inv['einvoice_details']) && isset($inv['einvoice_details']['status']) && ($inv['einvoice_details']['status'] == 'pushed')
-                                if($invoice_id !== "" ){
-                                  $organization_id = '776847408';
-                                  $result2=getheringInvoiceSubDetails($invoice_id,$organization_id,$headers_new);
-                                  $resall = json_decode($result2,true);
-                                  $res2[] = $resall['invoice'];
-                                }
-                            }
-                            $insert_count = 0;
-                            $update_count = 0;
-                            foreach($res2 as $rs)
-                            {
-                                $gst_no = $rs['gst_no'];
-                                $invoice_number = $rs['invoice_number'];
-                                $invoice_date = $rs['date']; 
-                                $status = $rs['status'];
-                                $due_date = $rs['due_date'];
-        
-                                 $invoice_time=$rs['created_time'];
-                                 $time_array = explode("T", $invoice_time);
-                                 $time_array = explode("+",$time_array[1]);
-                                 $invoice_time = $time_array[0];
-                                
-                                $sql_invoice_chk = $Zohobook_model->ip_invoices($invoice_number , $invoice_date);
-                                if($sql_invoice_chk <= 0)
-                                {  
-        
-                                        $gst_sql = $Zohobook_model->ip_clients($gst_no);
-                                        if($gst_sql)
-                                        {
-                                            $client_id = $gst_sql[0]['client_id'];
-                                            log_message('error', 'Data fetch success DB : ip_clients , client_id : '.$client_id);
-                                        }
-                                        else
-                                        {
-                                            log_message('error', 'No data => Data fetch failed DB : ip_clients '.$gst_no);
-                                            $gst_no_data['client_tax_code'] = $gst_no;
-                                            $gst_inserted_id = $Zohobook_model->customInsert($gst_no_data,'ip_clients');
-                                            $client_id = $gst_inserted_id;
-                                            log_message('error', 'New Data Created : DB : ip_clients , client_id : '.$client_id);
-                                        }
-        
-        
-                                        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
-                                        $charactersLength = strlen($characters);
-                                        $randomString = '';
-                                        for ($i = 0; $i < 16; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; }
-                                        $url_key = $randomString;
-            
-                                            $ip_invoices['user_id'] = 1;
-                                            $ip_invoices['client_id'] = $client_id;
-                                            $ip_invoices['invoice_group_id'] = 6;
-                                            $ip_invoices['invoice_status_id'] = ($status == 'draft' ? 1 : (($status == 'sent' || $status == 'overdue') ? 2 : 5));
-                                            $ip_invoices['invoice_date_created'] = $invoice_date;
-                                            $ip_invoices['invoice_time_created'] = $invoice_time;
-                                            $ip_invoices['invoice_date_due'] = $due_date;
-                                            $ip_invoices['invoice_number'] = $invoice_number;
-                                            $ip_invoices['invoice_url_key'] = $url_key;
-                                            $ip_invoices['receivedstatus'] = 'ST066';
-                                            $ip_invoices['credit_status'] = 0;
-                                        $invoice_insert_id = $Zohobook_model->customInsert($ip_invoices,'ip_invoices');
-                                        if($invoice_insert_id)
-                                        {
-                                            log_message('error', 'Data insert success DB : ip_invoices client id :'. $client_id);
-                                            $insert_count = $insert_count + 1;
-                                            //start invoice level custom fields
-        
-                                            //custom fields insert
-        
-                                             $batch_no = isset($rs['custom_fields'][5]['value']) ? $rs['custom_fields'][5]['value'] : "";
-                                                    // $batch_no = "";
-                                             $vehicle_number = isset($rs['custom_field_hash']['cf_vehicle_number']) ? $rs['custom_field_hash']['cf_vehicle_number']: '';
-                                             $transport_mode =isset($rs['custom_field_hash']['cf_transport_mode']) ? $rs['custom_field_hash']['cf_transport_mode'] : '';
-                                             $purchase_order_date = isset($rs['custom_field_hash']['cf_purchase_order_date'])?$rs['custom_field_hash']['cf_purchase_order_date']:'';
-                                             $driver = isset($rs['custom_field_hash']['cf_driver']) ? $rs['custom_field_hash']['cf_driver'] : '';
-                                             $place_of_supply = isset($rs['custom_field_hash']['cf_place_of_supply']) ? $rs['custom_field_hash']['cf_place_of_supply']:'';
-                                        // batch_no
-                                            $ip_invoice_custom_b['invoice_id'] = $invoice_insert_id;
-                                            $ip_invoice_custom_b['invoice_custom_fieldid'] = 62;
-                                            $ip_invoice_custom_b['invoice_custom_fieldvalue'] = $batch_no;
-                                            $result_invoice_custom_insert = $Zohobook_model->customInsert($ip_invoice_custom_b,'ip_invoice_custom');
-                                            if($result_invoice_custom_insert)
-                                                log_message('error', 'Data insert success DB : ip_invoice_custom ');
-                                            else
-                                                log_message('error', 'Data insert failed DB : ip_invoice_custom ');
-                                        // vehicle_number
-                                            $ip_invoice_custom_v['invoice_id'] = $invoice_insert_id;
-                                            $ip_invoice_custom_v['invoice_custom_fieldid'] = 8;
-                                            $ip_invoice_custom_v['invoice_custom_fieldvalue'] = $vehicle_number;
-                                            $res_vehicle = $Zohobook_model->customInsert($ip_invoice_custom_v,'ip_invoice_custom');
-                                            if($res_vehicle)
-                                                log_message('error', 'Data insert success DB : ip_invoice_custom ');
-                                            else
-                                                log_message('error', 'Data insert failed DB : ip_invoice_custom ');
-                                        // transport_mode
-                                            $ip_invoice_custom_t['invoice_id'] = $invoice_insert_id;
-                                            $ip_invoice_custom_t['invoice_custom_fieldid'] = 7;
-                                            $ip_invoice_custom_t['invoice_custom_fieldvalue'] = $transport_mode;
-                                            $res_transport_mode = $Zohobook_model->customInsert($ip_invoice_custom_t,'ip_invoice_custom');
-                                            if($res_transport_mode)
-                                                log_message('error', 'Data insert success DB : ip_invoice_custom ');
-                                            else
-                                                log_message('error', 'Data insert failed DB : ip_invoice_custom ');
-                                        // purchase_order_date
-                                            $ip_invoice_custom_p['invoice_id'] = $invoice_insert_id;
-                                            $ip_invoice_custom_p['invoice_custom_fieldid'] = 15;
-                                            $ip_invoice_custom_p['invoice_custom_fieldvalue'] = $purchase_order_date;
-                                            $res_purchase_order_date =$Zohobook_model->customInsert($ip_invoice_custom_p,'ip_invoice_custom');
-                                            if($res_purchase_order_date)
-                                                log_message('error', 'Data insert success DB : ip_invoice_custom ');
-                                            else
-                                                log_message('error', 'Data insert failed DB : ip_invoice_custom ');
-                                        // driver
-                                            $ip_invoice_custom_d['invoice_id'] = $invoice_insert_id;
-                                            $ip_invoice_custom_d['invoice_custom_fieldid'] = 58;
-                                            $ip_invoice_custom_d['invoice_custom_fieldvalue'] = $driver;
-                                            $res_driver = $Zohobook_model->customInsert($ip_invoice_custom_d,'ip_invoice_custom');
-                                            if($res_driver)
-                                                log_message('error', 'Data insert success DB : ip_invoice_custom ');
-                                            else
-                                                log_message('error', 'Data insert failed DB : ip_invoice_custom ');
-                                        // place_of_supply
-                                            $ip_invoice_custom_d['invoice_id'] = $invoice_insert_id;
-                                            $ip_invoice_custom_d['invoice_custom_fieldid'] = 10;
-                                            $ip_invoice_custom_d['invoice_custom_fieldvalue'] = $place_of_supply;
-                                            $res_place = $Zohobook_model->customInsert($ip_invoice_custom_d,'ip_invoice_custom');
-                                            if($res_place)
-                                                log_message('error', 'Data insert success DB : ip_invoice_custom ');
-                                            else
-                                                log_message('error', 'Data insert failed DB : ip_invoice_custom ');
-                                            //end  invoice level custom fields
-        
-                                            //if line items available
-                                            if(isset($rs['line_items']) && count($rs['line_items']) > 0)
-                                            {
-                                                log_message('error', 'Processing line items'.count($rs['line_items']));
-        
-                                                for($i = 0; $i< count($rs['line_items']);$i++)
-                                                {            //start insert line items
-                                                            $sku = $rs['line_items'][$i]['sku'];
-                                                            
-                                                            
-                                                            $item_price = $rs['line_items'][$i]['rate'];
-                                                            $item_order =  $rs['line_items'][$i]['item_order'];
-                                                            $item_product_unit = $rs['line_items'][$i]['unit'];
-                                                            $item_name = $rs['line_items'][$i]['name'];
-                                                            $item_description = $rs['line_items'][$i]['description'];
-                                                            $item_quantity = $rs['line_items'][$i]['quantity'];
-                                                            $cgst = $rs['line_items'][$i]['line_item_taxes'][1]['tax_name'];
-                                                            $sgst = $rs['line_items'][$i]['line_item_taxes'][0]['tax_name'];
-                                                            $cgst = $cgst[4];
-                                                            $sgst = $sgst[4];
-                                                            $cgst = $cgst.'.000';
-                                                            $getcgsttax = $Zohobook_model->ip_tax_rates($cgst);
-                                                            if($getcgsttax)
-                                                            {
-                                                                $cgsttaxid = $getcgsttax[0]['tax_rate_id'];
-                                                                log_message('error', 'Data fetch success DB : ip_tax_rates cgst'. $cgst);
-                                                            }
-                                                            else
-                                                            {
-                                                                log_message('error', 'No data => Data fetch failed DB : ip_tax_rates '. $cgst);
-                                                                $cgst_data['tax_rate_percent'] = $cgst;
-                                                                $getcgsttax = $Zohobook_model->customInsert($cgst_data,'ip_tax_rates');
-                                                                $cgsttaxid = $getcgsttax;
-                                                                log_message('error', 'New Data Created : DB : ip_tax_rates , tax_rate_id : '.$cgsttaxid);
-                                                            }
-                                
-                                                            $sgst = $sgst.'.000';
-                                                            $getsgsttax = $Zohobook_model->ip_tax_rates($sgst);
-                                                            if($getsgsttax)
-                                                            {
-                                                                $sgsttaxid = $getsgsttax[0]['tax_rate_id'];
-                                                                log_message('error', 'Data fetch success DB : ip_tax_rates sgst'. $sgst);
-                                                            }
-                                                            else
-                                                            {
-                                                                log_message('error', 'No data => Data fetch failed DB : ip_tax_rates '. $sgst);
-                                                                $sgst_data['tax_rate_percent'] = $sgst;
-                                                                $getsgsttax = $Zohobook_model->customInsert($sgst_data,'ip_tax_rates');
-                                                                $sgsttaxid = $getsgsttax;
-                                                                log_message('error', 'New Data Created : DB : ip_tax_rates , tax_rate_id : '.$sgsttaxid);
-                                                            }
-                                
-                                                            $item_subtotal = $rs['line_items'][$i]['item_total'];
-                                                           
-                                                           
-                                                            $item_sgst_amt = $rs['line_items'][$i]['line_item_taxes'][0]['tax_amount'];
-                                                            $item_cgst_amt = $rs['line_items'][$i]['line_item_taxes'][1]['tax_amount'];
-                                                            $item_tax_total = ($item_sgst_amt + $item_cgst_amt);
-                                                            $item_total = ($item_subtotal + $item_tax_total);
-                                
-                                                            $item_discount = 0.00;
-                                                            $item_igst_amt = 0.00;
-                                                            // if($batch_no==""){ $batch_no = "";}
-                                                            
-                                
-                                                            $sku_sql = $Zohobook_model->ip_products($sku);
-                                                            if(!empty($sku_sql))
-                                                            {
-                                                                $product_id = $sku_sql[0]['product_id'];
-                                                                log_message('error', 'Data fetch success DB : ip_products , product_id : '.$product_id);
-                                                            }
-                                                            else
-                                                            {
-                                                                log_message('error', 'No data => Data fetch failed DB : ip_products '. $sku);
-                                                                $sku_data['product_name'] = $item_name;
-                                                                $sku_data['product_description'] = $item_description;
-                                                                $sku_data['sku'] = $sku;
-                                                                $sku_inserted_id = $Zohobook_model->customInsert($sku_data,'ip_products');
-                                                                $product_id = $sku_inserted_id;
-                                                                log_message('error', '$sku_sql => Data fetch failed DB : ip_products '. $sku_sql);
+                    }
+                    $insert_count = 0;
+                    $update_count = 0;
+                    foreach($res2 as $rs)
+                    {
+                        $gst_no = $rs['gst_no'];
+                        $invoice_number = $rs['invoice_number'];
+                        $invoice_date = $rs['date']; 
+                        $status = $rs['status'];
+                        $due_date = $rs['due_date'];
+                        $invoice_url = $rs['invoice_url'];
+                        $einvoice_number = $rs['einvoice_details']['inv_ref_num'];
 
-                                                                log_message('error', 'sku'.$sku);
-                                                                log_message('error', 'New Data Created : DB : product_id , product_id : '.$product_id);
-                                                            }
-                                
-                                                            //#1
-                                
-                                                            $ip_invoice_items['invoice_id'] = $invoice_insert_id;
-                                                            $ip_invoice_items['item_product_id'] = $product_id;
-                                                            $ip_invoice_items['item_date_added'] = $invoice_date;
-                                                            $ip_invoice_items['item_name'] = $item_name;
-                                                            $ip_invoice_items['item_description'] = $item_description;
-                                                            $ip_invoice_items['item_quantity'] = $item_quantity;
-                                                            $ip_invoice_items['item_price'] = $item_price;
-                                                            $ip_invoice_items['item_order'] = $item_order;
-                                                            $ip_invoice_items['item_product_unit'] = $item_product_unit;
-                                                            $ip_invoice_items['Sgst_item_tax_rate_id'] = $sgsttaxid;
-                                                            $ip_invoice_items['Cgst_item_tax_rate_id'] = $cgsttaxid;
-                                                            $item_insert_id = $Zohobook_model->customInsert($ip_invoice_items,'ip_invoice_items');
-                                                            if($item_insert_id)
-                                                                log_message('error', 'Data insert success DB : ip_invoice_items => Sgst_item_tax_rate_id :'. $sgsttaxid);
-                                                            else
-                                                                log_message('error', 'Data insert failed DB : ip_invoice_items => Sgst_item_tax_rate_id :'. $sgsttaxid);
-                                
-                                                            //tax amount --  ip_invoice_item_amounts - table
-                                                                $ip_invoice_item_amounts['item_id'] = $item_insert_id;
-                                                                $ip_invoice_item_amounts['item_subtotal'] = $item_subtotal;
-                                                                $ip_invoice_item_amounts['item_tax_total'] = $item_tax_total;
-                                                                $ip_invoice_item_amounts['item_total'] = $item_total;
-                                                                $ip_invoice_item_amounts['item_sgst_amt'] = $item_sgst_amt;
-                                                                $ip_invoice_item_amounts['item_cgst_amt'] = $item_cgst_amt;
-                                                                $ip_invoice_item_amounts['item_discount'] = $item_discount;
-                                                                $ip_invoice_item_amounts['item_igst_amt'] = $item_igst_amt;
-                                                            $result_tax_amount_insert = $Zohobook_model->customInsert($ip_invoice_item_amounts,'ip_invoice_item_amounts');
-                                                            if($result_tax_amount_insert)
-                                                                log_message('error', 'Data insert success DB : ip_invoice_item_amounts ');
-                                                            else
-                                                                log_message('error', 'Data insert failed DB : ip_invoice_item_amounts ');
-                                                                
-                                                }         //end line items insert    
-        
-                                            }   
-                                            else
-                                            {
-                                                log_message('error', 'Line Items not found in API result');
-                                            }
-                                        }
-                                        else
-                                        {
-                                            log_message('error', 'Data insert failed DB : ip_invoice_items client id :'. $client_id);
-                                        }
-                                        
-                                        
-                                }   
-                                else // update invoice status, especially for cancelled invoices
+                            $invoice_time=$rs['created_time'];
+                            $time_array = explode("T", $invoice_time);
+                            $time_array = explode("+",$time_array[1]);
+                            $invoice_time = $time_array[0];
+                        
+                        $sql_invoice_chk = $Zohobook_model->ip_invoices($invoice_number , $invoice_date);
+                        if($sql_invoice_chk <= 0)
+                        {  
+
+                                $gst_sql = $Zohobook_model->ip_clients($gst_no);
+                                if($gst_sql)
                                 {
-                                    if($status == "void" || $status == "sent" ||  $status == "overdue")
+                                    $client_id = $gst_sql[0]['client_id'];
+                                    log_message('error', 'Data fetch success DB : ip_clients , client_id : '.$client_id);
+                                }
+                                else
+                                {
+                                    log_message('error', 'No data => Data fetch failed DB : ip_clients '.$gst_no);
+                                    $gst_no_data['client_tax_code'] = $gst_no;
+                                    $gst_inserted_id = $Zohobook_model->customInsert($gst_no_data,'ip_clients');
+                                    $client_id = $gst_inserted_id;
+                                    log_message('error', 'New Data Created : DB : ip_clients , client_id : '.$client_id);
+                                }
+
+
+                                $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+                                $charactersLength = strlen($characters);
+                                $randomString = '';
+                                for ($i = 0; $i < 16; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; }
+                                $url_key = $randomString;
+    
+                                    $ip_invoices['user_id'] = 1;
+                                    $ip_invoices['client_id'] = $client_id;
+                                    $ip_invoices['invoice_group_id'] = 6;
+                                    $ip_invoices['invoice_status_id'] = ($status == 'draft' ? 1 : (($status == 'sent' || $status == 'overdue') ? 2 : 5));
+                                    $ip_invoices['invoice_date_created'] = $invoice_date;
+                                    $ip_invoices['invoice_time_created'] = $invoice_time;
+                                    $ip_invoices['invoice_date_due'] = $due_date;
+                                    $ip_invoices['invoice_number'] = $invoice_number;
+                                    $ip_invoices['invoice_url_key'] = $url_key;
+                                    $ip_invoices['receivedstatus'] = 'ST066';
+                                    $ip_invoices['credit_status'] = 0;
+                                    $ip_invoices['status'] = $status;
+                                    $ip_invoices['e_invoice_number'] = $einvoice_number;
+                                    $ip_invoices['invoice_url'] = $invoice_url;
+                                $invoice_insert_id = $Zohobook_model->customInsert($ip_invoices,'ip_invoices');
+                                if($invoice_insert_id)
+                                {
+                                    log_message('error', 'Data insert success DB : ip_invoices client id :'. $client_id);
+                                    $insert_count = $insert_count + 1;
+                                    //start invoice level custom fields
+
+                                    //custom fields insert
+
+                                        $batch_no = isset($rs['custom_fields'][5]['value']) ? $rs['custom_fields'][5]['value'] : "";
+                                            // $batch_no = "";
+                                        $vehicle_number = isset($rs['custom_field_hash']['cf_vehicle_number']) ? $rs['custom_field_hash']['cf_vehicle_number']: '';
+                                        $transport_mode =isset($rs['custom_field_hash']['cf_transport_mode']) ? $rs['custom_field_hash']['cf_transport_mode'] : '';
+                                        $purchase_order_date = isset($rs['custom_field_hash']['cf_purchase_order_date'])?$rs['custom_field_hash']['cf_purchase_order_date']:'';
+                                        $driver = isset($rs['custom_field_hash']['cf_driver']) ? $rs['custom_field_hash']['cf_driver'] : '';
+                                        $place_of_supply = isset($rs['custom_field_hash']['cf_place_of_supply']) ? $rs['custom_field_hash']['cf_place_of_supply']:'';
+                                // batch_no
+                                    $ip_invoice_custom_b['invoice_id'] = $invoice_insert_id;
+                                    $ip_invoice_custom_b['invoice_custom_fieldid'] = 62;
+                                    $ip_invoice_custom_b['invoice_custom_fieldvalue'] = $batch_no;
+                                    $result_invoice_custom_insert = $Zohobook_model->customInsert($ip_invoice_custom_b,'ip_invoice_custom');
+                                    if($result_invoice_custom_insert)
+                                        log_message('error', 'Data insert success DB : ip_invoice_custom ');
+                                    else
+                                        log_message('error', 'Data insert failed DB : ip_invoice_custom ');
+                                // vehicle_number
+                                    $ip_invoice_custom_v['invoice_id'] = $invoice_insert_id;
+                                    $ip_invoice_custom_v['invoice_custom_fieldid'] = 8;
+                                    $ip_invoice_custom_v['invoice_custom_fieldvalue'] = $vehicle_number;
+                                    $res_vehicle = $Zohobook_model->customInsert($ip_invoice_custom_v,'ip_invoice_custom');
+                                    if($res_vehicle)
+                                        log_message('error', 'Data insert success DB : ip_invoice_custom ');
+                                    else
+                                        log_message('error', 'Data insert failed DB : ip_invoice_custom ');
+                                // transport_mode
+                                    $ip_invoice_custom_t['invoice_id'] = $invoice_insert_id;
+                                    $ip_invoice_custom_t['invoice_custom_fieldid'] = 7;
+                                    $ip_invoice_custom_t['invoice_custom_fieldvalue'] = $transport_mode;
+                                    $res_transport_mode = $Zohobook_model->customInsert($ip_invoice_custom_t,'ip_invoice_custom');
+                                    if($res_transport_mode)
+                                        log_message('error', 'Data insert success DB : ip_invoice_custom ');
+                                    else
+                                        log_message('error', 'Data insert failed DB : ip_invoice_custom ');
+                                // purchase_order_date
+                                    $ip_invoice_custom_p['invoice_id'] = $invoice_insert_id;
+                                    $ip_invoice_custom_p['invoice_custom_fieldid'] = 15;
+                                    $ip_invoice_custom_p['invoice_custom_fieldvalue'] = $purchase_order_date;
+                                    $res_purchase_order_date =$Zohobook_model->customInsert($ip_invoice_custom_p,'ip_invoice_custom');
+                                    if($res_purchase_order_date)
+                                        log_message('error', 'Data insert success DB : ip_invoice_custom ');
+                                    else
+                                        log_message('error', 'Data insert failed DB : ip_invoice_custom ');
+                                // driver
+                                    $ip_invoice_custom_d['invoice_id'] = $invoice_insert_id;
+                                    $ip_invoice_custom_d['invoice_custom_fieldid'] = 58;
+                                    $ip_invoice_custom_d['invoice_custom_fieldvalue'] = $driver;
+                                    $res_driver = $Zohobook_model->customInsert($ip_invoice_custom_d,'ip_invoice_custom');
+                                    if($res_driver)
+                                        log_message('error', 'Data insert success DB : ip_invoice_custom ');
+                                    else
+                                        log_message('error', 'Data insert failed DB : ip_invoice_custom ');
+                                // place_of_supply
+                                    $ip_invoice_custom_d['invoice_id'] = $invoice_insert_id;
+                                    $ip_invoice_custom_d['invoice_custom_fieldid'] = 10;
+                                    $ip_invoice_custom_d['invoice_custom_fieldvalue'] = $place_of_supply;
+                                    $res_place = $Zohobook_model->customInsert($ip_invoice_custom_d,'ip_invoice_custom');
+                                    if($res_place)
+                                        log_message('error', 'Data insert success DB : ip_invoice_custom ');
+                                    else
+                                        log_message('error', 'Data insert failed DB : ip_invoice_custom ');
+                                    //end  invoice level custom fields
+
+                                    //if line items available
+                                    if(isset($rs['line_items']) && count($rs['line_items']) > 0)
                                     {
-                                        $sql_invoice_update = array();
-                                        $sql_invoice_update['invoice_status_id'] = (($status == "sent" || $status == "overdue") ? 2 : 5);
-                                        // echo 'script' . $invoice_number. $status;
-                                        // print_r( $sql_invoice_update);
-                                        // echo '
'; - $sql_invoice_update = $Zohobook_model->sql_invoice_update($sql_invoice_update,$invoice_number,$invoice_date,'ip_invoices'); - if($sql_invoice_update) - { - log_message('error', 'Data update success DB : ip_invoices '); - } - else - { - log_message('error', 'Data update failed DB : ip_invoices '); - } - $update_count = $update_count + 1; + log_message('error', 'Processing line items'.count($rs['line_items'])); + + for($i = 0; $i< count($rs['line_items']);$i++) + { //start insert line items + $sku = $rs['line_items'][$i]['sku']; + + + $item_price = $rs['line_items'][$i]['rate']; + $item_order = $rs['line_items'][$i]['item_order']; + $item_product_unit = $rs['line_items'][$i]['unit']; + $item_name = $rs['line_items'][$i]['name']; + $item_description = $rs['line_items'][$i]['description']; + $item_quantity = $rs['line_items'][$i]['quantity']; + $cgst = $rs['line_items'][$i]['line_item_taxes'][1]['tax_name']; + $sgst = $rs['line_items'][$i]['line_item_taxes'][0]['tax_name']; + $cgst = $cgst[4]; + $sgst = $sgst[4]; + $cgst = $cgst.'.000'; + $getcgsttax = $Zohobook_model->ip_tax_rates($cgst); + if($getcgsttax) + { + $cgsttaxid = $getcgsttax[0]['tax_rate_id']; + log_message('error', 'Data fetch success DB : ip_tax_rates cgst'. $cgst); + } + else + { + log_message('error', 'No data => Data fetch failed DB : ip_tax_rates '. $cgst); + $cgst_data['tax_rate_percent'] = $cgst; + $getcgsttax = $Zohobook_model->customInsert($cgst_data,'ip_tax_rates'); + $cgsttaxid = $getcgsttax; + log_message('error', 'New Data Created : DB : ip_tax_rates , tax_rate_id : '.$cgsttaxid); + } + + $sgst = $sgst.'.000'; + $getsgsttax = $Zohobook_model->ip_tax_rates($sgst); + if($getsgsttax) + { + $sgsttaxid = $getsgsttax[0]['tax_rate_id']; + log_message('error', 'Data fetch success DB : ip_tax_rates sgst'. $sgst); + } + else + { + log_message('error', 'No data => Data fetch failed DB : ip_tax_rates '. $sgst); + $sgst_data['tax_rate_percent'] = $sgst; + $getsgsttax = $Zohobook_model->customInsert($sgst_data,'ip_tax_rates'); + $sgsttaxid = $getsgsttax; + log_message('error', 'New Data Created : DB : ip_tax_rates , tax_rate_id : '.$sgsttaxid); + } + + $item_subtotal = $rs['line_items'][$i]['item_total']; + + + $item_sgst_amt = $rs['line_items'][$i]['line_item_taxes'][0]['tax_amount']; + $item_cgst_amt = $rs['line_items'][$i]['line_item_taxes'][1]['tax_amount']; + $item_tax_total = ($item_sgst_amt + $item_cgst_amt); + $item_total = ($item_subtotal + $item_tax_total); + + $item_discount = 0.00; + $item_igst_amt = 0.00; + // if($batch_no==""){ $batch_no = "";} + + + $sku_sql = $Zohobook_model->ip_products($sku); + if(!empty($sku_sql)) + { + $product_id = $sku_sql[0]['product_id']; + log_message('error', 'Data fetch success DB : ip_products , product_id : '.$product_id); + } + else + { + log_message('error', 'No data => Data fetch failed DB : ip_products '. $sku); + $sku_data['product_name'] = $item_name; + $sku_data['product_description'] = $item_description; + $sku_data['sku'] = $sku; + $sku_inserted_id = $Zohobook_model->customInsert($sku_data,'ip_products'); + $product_id = $sku_inserted_id; + log_message('error', '$sku_sql => Data fetch failed DB : ip_products '. $sku_sql); + + log_message('error', 'sku'.$sku); + log_message('error', 'New Data Created : DB : product_id , product_id : '.$product_id); + } + + //#1 + + $ip_invoice_items['invoice_id'] = $invoice_insert_id; + $ip_invoice_items['item_product_id'] = $product_id; + $ip_invoice_items['item_date_added'] = $invoice_date; + $ip_invoice_items['item_name'] = $item_name; + $ip_invoice_items['item_description'] = $item_description; + $ip_invoice_items['item_quantity'] = $item_quantity; + $ip_invoice_items['item_price'] = $item_price; + $ip_invoice_items['item_order'] = $item_order; + $ip_invoice_items['item_product_unit'] = $item_product_unit; + $ip_invoice_items['Sgst_item_tax_rate_id'] = $sgsttaxid; + $ip_invoice_items['Cgst_item_tax_rate_id'] = $cgsttaxid; + $item_insert_id = $Zohobook_model->customInsert($ip_invoice_items,'ip_invoice_items'); + if($item_insert_id) + log_message('error', 'Data insert success DB : ip_invoice_items => Sgst_item_tax_rate_id :'. $sgsttaxid); + else + log_message('error', 'Data insert failed DB : ip_invoice_items => Sgst_item_tax_rate_id :'. $sgsttaxid); + + //tax amount -- ip_invoice_item_amounts - table + $ip_invoice_item_amounts['item_id'] = $item_insert_id; + $ip_invoice_item_amounts['item_subtotal'] = $item_subtotal; + $ip_invoice_item_amounts['item_tax_total'] = $item_tax_total; + $ip_invoice_item_amounts['item_total'] = $item_total; + $ip_invoice_item_amounts['item_sgst_amt'] = $item_sgst_amt; + $ip_invoice_item_amounts['item_cgst_amt'] = $item_cgst_amt; + $ip_invoice_item_amounts['item_discount'] = $item_discount; + $ip_invoice_item_amounts['item_igst_amt'] = $item_igst_amt; + $result_tax_amount_insert = $Zohobook_model->customInsert($ip_invoice_item_amounts,'ip_invoice_item_amounts'); + if($result_tax_amount_insert) + log_message('error', 'Data insert success DB : ip_invoice_item_amounts '); + else + log_message('error', 'Data insert failed DB : ip_invoice_item_amounts '); + + } //end line items insert + + } + else + { + log_message('error', 'Line Items not found in API result'); } } - // echo 'new invoice inserted count- ' . $insert_count . '/' . 'status updated count - ' . $update_count; + else + { + log_message('error', 'Data insert failed DB : ip_invoice_items client id :'. $client_id); + } + + + } + else // update invoice status, especially for cancelled invoices + { + // if($status == "void" || $status == "sent" || $status == "overdue") + // { + $sql_invoice_update = array(); + $sql_invoice_update['invoice_status_id'] = (($status == "sent" || $status == "overdue") ? 2 : 5); + // echo 'script' . $invoice_number. $status; + // print_r( $sql_invoice_update); + // echo '
'; + $sql_invoice_update = $Zohobook_model->sql_invoice_update($sql_invoice_update,$invoice_number,$invoice_date,'ip_invoices'); + if($sql_invoice_update) + { + log_message('error', 'Data update success DB : ip_invoices '); + } + else + { + log_message('error', 'Data update failed DB : ip_invoices '); + } + $update_count = $update_count + 1; + // } + } + // echo 'new invoice inserted count- ' . $insert_count . '/' . 'status updated count - ' . $update_count; - }$response = [ - 'status' => true, - 'message' => "Successfully data inserted. Total inserted: " . $insert_count . ", Total Updated: " . $update_count - ]; - return json_encode($response); - - // curl_close($ch); - // } - } - catch (\Exception $e) { - $data['err'] = $e->getMessage(); - // $db = \Config\Database::connect(); - // $data['last_query'] = $db->getLastQuery();; - $Zohobook_model->customInsert($data,'zohobook_api_err'); - log_message('error', "Data insertion failed : " . $e->getMessage()); - - return json_encode("Data insertion failed : " . $e->getMessage()); - } - } - // END zoho API -} \ No newline at end of file + }$response = [ + 'status' => true, + 'message' => "Successfully data inserted. Total inserted: " . $insert_count . ", Total Updated: " . $update_count + ]; + return json_encode($response); + + // curl_close($ch); + // } + } + catch (\Exception $e) { + $data['err'] = $e->getMessage(); + // $db = \Config\Database::connect(); + // $data['last_query'] = $db->getLastQuery();; + $Zohobook_model->customInsert($data,'zohobook_api_err'); + log_message('error', "Data insertion failed : " . $e->getMessage()); + + return json_encode("Data insertion failed : " . $e->getMessage()); + } + } + // END zoho API + +} \ No newline at end of file diff --git a/app/Helpers/zohobook_helper.php b/app/Helpers/zohobook_helper.php index c292d4e9..bfce0ba3 100755 --- a/app/Helpers/zohobook_helper.php +++ b/app/Helpers/zohobook_helper.php @@ -77,7 +77,6 @@ if (! function_exists('getheringInvoiceDetails')) { // Store headers and data $data['headers_new'] = $headers; $data['data'] = curl_exec($ch); - // Return data return $data; } diff --git a/app/Models/Department_model.php b/app/Models/Department_model.php index 19788715..e306a6f2 100644 --- a/app/Models/Department_model.php +++ b/app/Models/Department_model.php @@ -51,7 +51,7 @@ class Department_model extends Model function departmentListing() { $builder = $this->db->table('t_departmentdetails as BaseT') - ->select('BaseT.DepartmentName, BaseT.DEPCode, BaseT.HeadDept, BaseT.IsActive') + ->select('BaseT.CreatedDt,BaseT.DepartmentName, BaseT.DEPCode, BaseT.HeadDept, BaseT.IsActive') ->orderBy("BaseT.DEPCode", "asc"); $query =$builder->get(); $result = $query->getResult(); diff --git a/app/Models/Inwardgateregister_model.php b/app/Models/Inwardgateregister_model.php index 1fdc17ce..a16e5246 100755 --- a/app/Models/Inwardgateregister_model.php +++ b/app/Models/Inwardgateregister_model.php @@ -153,7 +153,7 @@ class Inwardgateregister_model extends Model ->join('t_purchaseorder_lineitem POL', 'POL.PONO = POM.PONO') ->join('t_supplierdetailsn sup', 'POM.SupplierID = sup.SupplierID') ->join('t_ogr_master OGM ', 'POM.PONO = OGM.PONO_INV', 'left') - ->where('POM.POType !=', SERVICE) + // ->where('POM.POType !=', SERVICE) // due to client requirements - he wants to remove the conidition. ->where('POM.Status', PO_RELEASED) ->orWhere('POM.Status',REQITEM_Emergency_PO_CREATED) ->orWhere('POM.Status',IGR_CREATED) @@ -164,10 +164,48 @@ class Inwardgateregister_model extends Model $query = $builder->get(); $result = $query->getResult(); + // echo $this->db->getLastQuery()->getQuery(); die; return $result; } + function checkdrivername($dr) + { + $temp[] = ''; + $builder = $this->db->table('t_igr_master') + ->distinct() + ->select('DriverName') + ->like('DriverName', $dr); + $query = $builder->get(); + $temparr[] = ''; + foreach ($query->getResult() as $arr) { + $temparr[] = $arr->DriverName; + } + $temp['suggestions'] = $temparr; + + return $temp; + } + + public function checkdriverMobile($mobile,$driverName) { + $builder = $this->db->table('t_igr_master') + ->distinct() + ->select('DriverMobileNumber') + ->like('DriverMobileNumber', $mobile); + if($driverName){ + $builder->where('DriverName', $driverName); + } + + + $query = $builder->get(); + $temparr[] = ''; + foreach ($query->getResult() as $arr) { + $temparr[] = $arr->DriverMobileNumber; + } + // echo $this->db->getLastQuery()->getQuery();die; + $temp['suggestions'] = $temparr; + + return $temp; + } function viewpurchaseorder($PO) { @@ -328,11 +366,10 @@ class Inwardgateregister_model extends Model ->join('t_purchaseorder_master PO', 'igr.PONO = PO.PONO') ->join('t_supplierdetailsn` sup', 'PO.SupplierID = sup.SupplierID') ->where('igr.IGRStatus !=', MRIR_CREATED) - ->where('PO.IsQualityChkReqired', 1) ->orderBy('igr.CreatedDate', 'desc'); $query = $builder->get(); $result = $query->getResult(); - + // echo $this->db->getLastQuery()->getQuery();die; return $result; } @@ -346,7 +383,7 @@ class Inwardgateregister_model extends Model $builder = $this->db->table('t_igr_master igr') ->distinct() - ->select('igr.IGRNO,igr.*,igrd.*,MM.MaterialName,MM.UOM,sup.Address,sup.SupplierName,POM.ServiceDescription,POL.Quantity,POM.POType') + ->select('igr.IGRNO,igr.*,igrd.*,MM.MaterialName,MM.UOM,sup.Address,sup.SupplierName,POM.ServiceDescription,POL.Quantity,POM.POType,POM.IsOpenOrder') ->join('t_igr_details igrd', 'igrd.IGRNO = igr.IGRNO') ->join('t_purchaseorder_master POM', 'igr.PONO = POM.PONO') ->join('t_purchaseorder_lineitem POL', 'igr.PONO = POL.PONO and POL.MaterialCode=igrd.MaterialCode ') diff --git a/app/Models/Ipattachment_model.php b/app/Models/Ipattachment_model.php new file mode 100644 index 00000000..76708b57 --- /dev/null +++ b/app/Models/Ipattachment_model.php @@ -0,0 +1,78 @@ +db->transStart(); + $builder = $this->db->table('ip_invoice_attachment'); + $builder->insert($attachments); + + $insert_id = $this->db->affectedRows(); + + $this->db->transComplete(); + + return $insert_id; + } + + + + + + + // Ipinvoice_model + public function deleteAttachment($invoice_attachment_id) { + // Get the attachment details to get the file path + $builder = $this->db->table('ip_invoice_attachment'); + $builder->where('invoice_attachment_id', $invoice_attachment_id); + $query = $builder->get(); + $attachment = $query->getRowArray(); // Get single row as an associative array + + if ($attachment) { + // Construct the file path + $fileName = $attachment['attachment_name']; // Make sure this is the correct field name + $filePath = './public/uploads/images/invoice_files/' . $fileName; + + // Debug: Log the file path + log_message('error', 'Attempting to delete file: ' . $filePath); + + // Check if the path is actually a file + if (file_exists($filePath) && !is_dir($filePath)) { + unlink($filePath); // Delete the file + } else { + log_message('error', 'File does not exist or is a directory: ' . $filePath); + } + + // Delete the record from the database + $builder->where('invoice_attachment_id', $invoice_attachment_id); + $builder->delete(); + + return $this->db->affectedRows() > 0; + } + + return false; + } + + + + + + +} \ No newline at end of file diff --git a/app/Models/Ipinvoice_model.php b/app/Models/Ipinvoice_model.php new file mode 100644 index 00000000..5cda73e9 --- /dev/null +++ b/app/Models/Ipinvoice_model.php @@ -0,0 +1,441 @@ +db->table('ip_invoices') + ->select('ip_invoices.invoice_id, ip_invoices.user_id, ip_invoices.client_id, + ip_invoices.invoice_group_id, ip_invoices.invoice_status_id, ip_invoices.invoice_date_due, ip_invoices.invoice_date_created, + ip_invoices.invoice_number, ip_invoices.invoice_terms, ip_invoices.status, ip_invoices.e_invoice_number, ip_invoices.invoice_url, ip_clients.client_name, + ip_payment_methods.payment_method_name, ip_users.user_name, + ip_products.product_name, ip_invoice_items.item_price, ip_products.cgst, ip_products.sgst, + ip_invoice_items.item_quantity, ip_invoice_items.item_price, ip_invoice_items.item_name, ip_invoice_items.item_quantity, + ip_invoice_amounts.invoice_total, ip_invoice_amounts.invoice_item_subtotal, ip_invoice_amounts.invoice_item_tax_total') + ->join('ip_payment_methods', 'ip_invoices.payment_method = ip_payment_methods.payment_method_id', 'left') + ->join('ip_clients', 'ip_invoices.client_id = ip_clients.client_id', 'left') + ->join('ip_users', 'ip_invoices.user_id = ip_users.user_id', 'left') + ->join('ip_invoice_items', 'ip_invoices.invoice_id = ip_invoice_items.invoice_id', 'left') + ->join('ip_products', 'ip_invoice_items.item_product_id = ip_products.product_id', 'left') + ->join('ip_invoice_amounts', 'ip_invoices.invoice_id = ip_invoice_amounts.invoice_id', 'left') + ->orderBy('ip_invoices.invoice_number', 'DESC'); + + $query = $builder->get(); + $result = $query->getResult(); + // $results = $query->getResultArray(); + return $result; + // $invoices = []; + + // foreach ($results as $row) { + // $invoice_id = $row['invoice_id']; + + // // If the invoice_id doesn't exist in the $invoices array, initialize it + // if (!isset($invoices[$invoice_id])) { + // $invoices[$invoice_id] = [ + // 'invoice_id' => $row['invoice_id'], + // 'user_id' => $row['user_id'], + // 'client_id' => $row['client_id'], + // 'invoice_group_id' => $row['invoice_group_id'], + // 'invoice_status_id' => $row['invoice_status_id'], + // 'invoice_date_due' => $row['invoice_date_due'], + // 'invoice_date_created' => $row['invoice_date_created'], + // 'invoice_number' => $row['invoice_number'], + // 'invoice_terms' => $row['invoice_terms'], + // 'status' => $row['status'], + // 'e_invoice_number' => $row['e_invoice_number'], + // 'invoice_url' => $row['invoice_url'], + // 'client_name' => $row['client_name'], + // 'payment_method_name' => $row['payment_method_name'], + // 'user_name' => $row['user_name'], + // 'invoice_total' => $row['invoice_total'], + // 'invoice_item_subtotal' => $row['invoice_item_subtotal'], + // 'invoice_item_tax_total' => $row['invoice_item_tax_total'], + // 'products' => [] // Initialize the products array + // ]; + // } + + // // Add the product to the products array for the current invoice + // $invoices[$invoice_id]['products'][] = [ + // 'product_name' => $row['product_name'], + // 'item_quantity' => $row['item_quantity'], + // 'item_price' => $row['item_price'], + // ]; + // } + + // // Return the grouped invoices + // return $invoices; + } + + + + + + + /** + * This function is used to add new user to system + * @return number $insert_id : This is last inserted id + */ + function addNewUser($userInfo) + { + + $this->db->transStart(); + $builder = $this->db->table('tbl_users'); + $builder->insert($userInfo); + + $insert_id = $this->db->affectedRows(); + + $this->db->transComplete(); + + return $insert_id; + } + + /** + * This function used to get user information by id + * @param number $userId : This is user id + * @return array $result : This is user information + */ + function getInvoice($invoiceId) + { + $builder = $this->db->table('ip_invoices') + // ->select('') + ->where('invoice_id', $invoiceId); + $query = $builder->get(); + + return $query->getResult(); + } + + + /** + * This function used to get user information by id + * @param number $userId : This is user id + * @return array $result : This is user information + */ + function getinvoiceAttachment($invoiceId) + { + $builder = $this->db->table('ip_invoice_attachment') + // ->select('') + ->where('invoice_id', $invoiceId); + $query = $builder->get(); + + return $query->getResult(); + } + + + // Ipinvoice_model + public function deleteAttachment($invoice_attachment_id) { + // Get the attachment details to get the file path + $builder = $this->db->table('ip_invoice_attachment'); + $builder->where('invoice_attachment_id', $invoice_attachment_id); + $query = $builder->get(); + $attachment = $query->getRowArray(); // Get single row as an associative array + + if ($attachment) { + // Construct the file path + $fileName = $attachment['attachment_name']; // Make sure this is the correct field name + $filePath = './public/uploads/images/invoice_files/' . $fileName; + + // Debug: Log the file path + log_message('error', 'Attempting to delete file: ' . $filePath); + + // Check if the path is actually a file + if (file_exists($filePath) && !is_dir($filePath)) { + unlink($filePath); // Delete the file + } else { + log_message('error', 'File does not exist or is a directory: ' . $filePath); + } + + // Delete the record from the database + $builder->where('invoice_attachment_id', $invoice_attachment_id); + $builder->delete(); + + return $this->db->affectedRows() > 0; + } + + return false; + } + + + + + + + /** + * This function is used to update the user information + * @param array $userInfo : This is users updated information + * @param number $userId : This is user id + */ + function editUser($userInfo, $userId) + { + $this->db->table('tbl_users') + ->where('EmpID', $userId) + ->update($userInfo); + + return TRUE; + } + + + + /** + * This function is used to delete the user information + * @param number $userId : This is user id + * @return boolean $result : TRUE / FALSE + */ + function deleteUser($userId, $userInfo) + { + $this->db->table('tbl_users') + ->where('userId', $userId) + ->update($userInfo); + + return $this->db->affectedRows(); + } + + + + + /** + * This function is used to get the All employees + * @return array $result : This is result of the query + */ + function getAllEmployees() + { + /*->select('EmpID,FirstName,LastName'); + $builder = $this->db->table('t_employee_details'); + $query = $builder->get(); + + return $query->getResult(); */ + $builder = $this->db->table('t_employee_details EMP') + ->select('EMP.EmpID,EMP.FirstName,EMP.LastName,EMP.Designation,EMP.EmailId,EMP.ContactNumber,DEPT.DEPCode,DEPT.DepartmentName') + ->join('t_departmentdetails DEPT', 'EMP.Departmentcode = DEPT.DEPCode') + ->where('EMP.IsActive ', 1); + $query = $builder->get(); + return $query->getResult(); + } + + + /** + * This function is used to get the Today Sales + * @return array $result : This is result of the query + */ + function todaySales() + { + $builder = $this->db->table('ip_invoices a') + ->select('COUNT(DISTINCT(a.invoice_number)) as Invoices, IFNULL(SUM(b.item_quantity), 0) as Qty, IFNULL(SUM(c.item_subtotal), 0) as Sales') + ->join('ip_invoice_items b', 'a.invoice_id = b.invoice_id', 'left') + ->join('ip_invoice_item_amounts c', 'b.item_id = c.item_id', 'left') + ->where('a.invoice_date_created', date('Y-m-d')) + ->where('a.invoice_status_id', 2); + + $query = $builder->get(); + return $query->getRow(); // Assuming you want a single row of aggregated results + } + + + /** + * This function is used to get the This Month Sales + * @return array $result : This is result of the query + */ + function thisMonthSales() + { + // Calculate the start date for the current fiscal month + $fiscalMonthStart = date('Y') . '-04-01'; // Assuming the fiscal year starts in April + $currentYear = date('Y'); + $currentMonth = date('m'); + + // If the current month is before April, subtract one year for the fiscal year start + if ($currentMonth < 4) { + $fiscalMonthStart = ($currentYear - 1) . '-' . $currentMonth . '-01'; + } else { + $fiscalMonthStart = $currentYear . '-' . $currentMonth . '-01'; + } + + // Build the query + $builder = $this->db->table('ip_invoices a') + ->select('COUNT(DISTINCT(a.invoice_number)) as Invoices, + IFNULL(SUM(b.item_quantity), 0) as Qty, + IFNULL(SUM(c.item_subtotal), 0) as Sales') + ->join('ip_invoice_items b', 'a.invoice_id = b.invoice_id', 'left') + ->join('ip_invoice_item_amounts c', 'b.item_id = c.item_id', 'left') + ->where('a.invoice_date_created >=', $fiscalMonthStart) + ->where('a.invoice_status_id', 2); + + // Execute the query + $query = $builder->get(); + + // Log the SQL query for debugging + log_message('debug', $builder->getCompiledSelect()); + + // Return the aggregated results + return $query->getRow(); + } + + /** + * This function is used to get the This Year Sales + * @return array $result : This is result of the query + */ + function thisYearSales() + { + // Calculate the start date for the current fiscal year + $fiscalYearStart = date('Y') . '-04-01'; + $currentYear = date('Y'); + $currentMonth = date('m'); + + // If the current month is before April, subtract one year for the fiscal year start + if ($currentMonth < 4) { + $fiscalYearStart = ($currentYear - 1) . '-04-01'; + } else { + $fiscalYearStart = $currentYear . '-04-01'; + } + + // Build the query + $builder = $this->db->table('ip_invoices a') + ->select('COUNT(DISTINCT(a.invoice_number)) as Invoices, + IFNULL(SUM(b.item_quantity), 0) as Qty, + IFNULL(SUM(c.item_subtotal), 0) as Sales') + ->join('ip_invoice_items b', 'a.invoice_id = b.invoice_id', 'left') + ->join('ip_invoice_item_amounts c', 'b.item_id = c.item_id', 'left') + ->where('a.invoice_date_created >=', $fiscalYearStart) + ->where('a.invoice_status_id', 2); + + // Execute the query + $query = $builder->get(); + + // Log the SQL query for debugging + log_message('debug', $builder->getCompiledSelect()); + + // Return the aggregated results + return $query->getRow(); + } + + /** + * This function is used to get the This Year Sales Trend + * @return array $result : This is result of the query + */ + function thisYearSalesTrend() + { + $currentYear = date('Y'); + $currentMonth = date('m'); + + // Calculate the start date for the current and last fiscal years + if ($currentMonth < 4) { + $fiscalYearStartCurrent = ($currentYear - 1) . '-04-01'; + $fiscalYearStartLast = ($currentYear - 2) . '-04-01'; + $fiscalYearEndLast = ($currentYear - 1) . '-03-31'; + } else { + $fiscalYearStartCurrent = $currentYear . '-04-01'; + $fiscalYearStartLast = ($currentYear - 1) . '-04-01'; + $fiscalYearEndLast = $currentYear . '-03-31'; + } + + // Build query for the current fiscal year + $builderCurrent = $this->db->table('ip_invoices a') + ->select("DATE_FORMAT(a.invoice_date_created, '%b') as Month, + IFNULL(SUM(c.item_total), 0) as Sales") + ->join('ip_invoice_items b', 'a.invoice_id = b.invoice_id', 'left') + ->join('ip_invoice_item_amounts c', 'b.item_id = c.item_id', 'left') + ->where('a.invoice_date_created >=', $fiscalYearStartCurrent) + ->where('a.invoice_status_id', 2) + ->groupBy("DATE_FORMAT(a.invoice_date_created, '%b')") + ->orderBy('MONTH(a.invoice_date_created)'); + + // Build query for the last fiscal year + $builderLast = $this->db->table('ip_invoices a') + ->select("DATE_FORMAT(a.invoice_date_created, '%b') as Month, + IFNULL(SUM(c.item_total), 0) as Sales") + ->join('ip_invoice_items b', 'a.invoice_id = b.invoice_id', 'left') + ->join('ip_invoice_item_amounts c', 'b.item_id = c.item_id', 'left') + ->where('a.invoice_date_created >=', $fiscalYearStartLast) + ->where('a.invoice_date_created <', $fiscalYearStartCurrent) + ->where('a.invoice_status_id', 2) + ->groupBy("DATE_FORMAT(a.invoice_date_created, '%b')") + ->orderBy('MONTH(a.invoice_date_created)'); + + // Execute the queries + $currentYearData = $builderCurrent->get()->getResultArray(); + $lastYearData = $builderLast->get()->getResultArray(); + + // Combine the data + $salesComparison = []; + foreach ($lastYearData as $lastYearRow) { + $month = $lastYearRow['Month']; + $salesComparison[$month]['Last Year'] = $lastYearRow['Sales']; + } + + foreach ($currentYearData as $currentYearRow) { + $month = $currentYearRow['Month']; + $salesComparison[$month]['Current Year'] = $currentYearRow['Sales']; + } + + // Log the SQL queries for debugging + log_message('debug', $builderCurrent->getCompiledSelect()); + log_message('debug', $builderLast->getCompiledSelect()); + + // Return the comparison results + return $salesComparison; + } + + /** + * This function is used to get the Today invoices + * @return array $result : This is result of the query + */ + function getTodayInvoices() + { + // Define the custom field ID for the vehicle number + $vehicleCustomFieldId = 8; // Adjust this ID if necessary + + // Build the query to get today's invoices with detailed information + $builder = $this->db->table('ip_invoices ii') + ->select(" + ii.invoice_number AS 'Invoice No.', + DATE_FORMAT(ii.invoice_date_created, '%d-%m-%Y') AS 'Invoice Date', + TIME_FORMAT(ii.invoice_time_created, '%l:%i %p') AS 'Invoice Time', + icf.invoice_custom_fieldvalue AS 'Vehicle No.', + IF(iit.item_description = '', iit.item_name, iit.item_description) AS 'Product', + ic.client_name AS 'Client', + SUM(iit.item_quantity) AS 'Quantity', + SUM(iit.item_price) AS 'Rate', + SUM(iia.item_subtotal) AS 'Value', + SUM(iia.item_cgst_amt) AS 'CGST', + SUM(iia.item_sgst_amt) AS 'SGST', + SUM(iia.item_igst_amt) AS 'IGST', + SUM(IFNULL(tcs.tax_rate_percent * iia.item_total / 100, 0)) AS 'TCS', + SUM(IFNULL(tcs.tax_rate_percent * iia.item_total / 100, 0)) + SUM(iia.item_total) AS 'Total' + ") + ->join('ip_invoice_custom icf', 'icf.invoice_id = ii.invoice_id', 'left') + ->join('ip_invoice_tax_rates tc', 'tc.invoice_id = ii.invoice_id', 'left') + ->join('ip_invoice_items iit', 'iit.invoice_id = ii.invoice_id', 'left') + ->join('ip_invoice_item_amounts iia', 'iia.item_id = iit.item_id', 'left') + ->join('ip_clients ic', 'ic.client_id = ii.client_id', 'left') + ->join('ip_tax_rates sgst', 'sgst.tax_rate_id = iit.sgst_item_tax_rate_id', 'left') + ->join('ip_tax_rates cgst', 'cgst.tax_rate_id = iit.cgst_item_tax_rate_id', 'left') + ->join('ip_tax_rates igst', 'igst.tax_rate_id = iit.igst_item_tax_rate_id', 'left') + ->join('ip_tax_rates tcs', 'tcs.tax_rate_id = tc.tax_rate_id', 'left') + ->where('icf.invoice_custom_fieldid', $vehicleCustomFieldId) + ->where('ii.invoice_status_id', 2) + ->where('ii.invoice_date_created', date('Y-m-d')) + ->groupBy('ii.invoice_number, iit.item_description') + ->orderBy('ii.invoice_number'); + + // Execute the query + $query = $builder->get(); + + // Log the SQL query for debugging + log_message('debug', $builder->getCompiledSelect()); + + // Return the detailed invoice data + return $query->getResultArray(); + } + +} \ No newline at end of file diff --git a/app/Models/Purchaseorder_model.php b/app/Models/Purchaseorder_model.php index 440ef89b..b9898986 100644 --- a/app/Models/Purchaseorder_model.php +++ b/app/Models/Purchaseorder_model.php @@ -1578,7 +1578,7 @@ QuantityRejected,ROUND(Quantity-ReceivedQuantity)as PendingQty,Per, $builder = $this->db->table('t_purchaseorder_master mast')->distinct() - ->select('mast.PONO,mast.TotalOrderValue,st.StatusCode,st.StatusName,emp.FirstName,mast.CreatedDate,ccm.CostCenterName,ccm.CostCenterCode,mast.POType as RType,mast.Remarks,DepartmentName,mast.ApprovedBy,(select EmpID from tbl_users where userId=mast.ApprovedBy )as EID,rmast.ReqType,mast.Status,mast.CapitalRange, + ->select('mast.PODate,mast.PONO,mast.TotalOrderValue,st.StatusCode,st.StatusName,emp.FirstName,mast.CreatedDate,ccm.CostCenterName,ccm.CostCenterCode,mast.POType as RType,mast.Remarks,DepartmentName,mast.ApprovedBy,(select EmpID from tbl_users where userId=mast.ApprovedBy )as EID,rmast.ReqType,mast.Status,mast.CapitalRange, (select FirstName from t_employee_details where EmpID=EID)as Approver,sup.SupplierName,sup.MSME') // ->orderBy('mast.Status',"PO_CREATED"); diff --git a/app/Models/User_model.php b/app/Models/User_model.php index cf61f531..d51487b4 100644 --- a/app/Models/User_model.php +++ b/app/Models/User_model.php @@ -18,7 +18,7 @@ class User_model extends Model function userListing() { $builder = $this->db->table('t_employee_details EMP') - ->select('EMP.EmpID,EMP.FirstName,EMP.LastName,EMP.Designation,EMP.EmailId,EMP.ContactNumber, + ->select('user.createdDtm,EMP.EmpID,EMP.FirstName,EMP.LastName,EMP.Designation,user.email as EmailId,EMP.ContactNumber, DEPT.DEPCode,DEPT.DepartmentName,role.role,user.userId') ->join('t_departmentdetails DEPT', 'EMP.Departmentcode = DEPT.DEPCode') ->join('tbl_users user', 'user.EmpID = EMP.EmpID') diff --git a/app/Views/AmendPOlist.php b/app/Views/AmendPOlist.php index 932105d0..e9fdfd32 100644 --- a/app/Views/AmendPOlist.php +++ b/app/Views/AmendPOlist.php @@ -5,6 +5,40 @@ margin: 0px !important; } +
@@ -20,13 +54,25 @@
+
+ + + + + + + + + +
+
- - + + @@ -44,12 +90,12 @@ ?> - - + + @@ -121,7 +167,7 @@ - --> + + \ No newline at end of file diff --git a/app/Views/EditservicePurchaseorder.php b/app/Views/EditservicePurchaseorder.php index 26d5cc45..50bf0d6d 100644 --- a/app/Views/EditservicePurchaseorder.php +++ b/app/Views/EditservicePurchaseorder.php @@ -1986,7 +1986,7 @@ if (!empty($getlogpodtl)) { - + @@ -2022,7 +2022,7 @@ if (!empty($getlogpodtl)) { - + @@ -2477,10 +2477,6 @@ if (!empty($getlogpodtl)) { - - - -
PONO#PO Type PO DatePONOPO Type Supplier Name Total Order Value PO Status
PONO ?>ReqType ?> PODate); $PODate = $Pdt->format('d-m-Y'); echo $PODate ?>PONO ?>ReqType ?> SupplierName ?> TotalOrderValue ?> SNo Requisition No Item CodeItem DescriptionItem Name Quantity UOM Rate ReqNo ?> MaterialCode ?>ServiceMaterialDescription ?>MaterialName ?> Quantity ?> UOM ?><%=BasicAmount%> <%=Taxvalue%> <%=TotalValue%><%=ActualQuantity%><%=ReceivedQuantity%><%=PendingQuantity%>     @@ -2580,16 +2576,13 @@ if (!empty($getlogpodtl)) { index: temp, ReqNo: Reqnumber, MaterialCode: materialCode, - MaterialName: ServiceDescription, + MaterialName: materialName, Quantity: quantity, UOM: uom, Rate: itemRate, BasicAmount: basicval, Taxvalue: TotalTaxValue, - TotalValue: TotalOrderValue, - ActualQuantity: quantity, - ReceivedQuantity: 0, - PendingQuantity: quantity + TotalValue: TotalOrderValue })); @@ -2684,7 +2677,7 @@ if (!empty($getlogpodtl)) { var cellval = tr.cells; cellval[2].innerHTML = editMaterialCode; - cellval[3].innerHTML = ServiceDescription; + cellval[3].innerHTML = editDescription; cellval[4].innerHTML = editQuantity; cellval[5].innerHTML = editUOM; cellval[6].innerHTML = parseFloat(itemRate).toFixed(2); diff --git a/app/Views/POlist.php b/app/Views/POlist.php index 385c6dd5..35ded5e0 100644 --- a/app/Views/POlist.php +++ b/app/Views/POlist.php @@ -32,6 +32,29 @@ white-space: nowrap; } +
@@ -85,7 +108,6 @@ - @@ -105,7 +127,6 @@ $index = $index + 1; ?> -
PO Date PONO# PO Type
PODate ?> PODate); $PODate = $Pdt->format('d-m-Y'); echo $PODate @@ -184,25 +205,58 @@ + + + + + + + + - - + + \ No newline at end of file diff --git a/app/Views/configlisting.php b/app/Views/configlisting.php index 87a2a395..eb9978ea 100644 --- a/app/Views/configlisting.php +++ b/app/Views/configlisting.php @@ -1,100 +1,154 @@ -
-
-
-
-

Configuration Details

-
-
-
- -
-
- + .Date-filter-form { + display: flex; + align-items: center; + gap: 10px; + /* Adjust the gap as needed */ + } + + .Date-filter-form input, + .Date-filter-form button { + padding: 5px; + font-size: 14px; + } + + .Date-filter-form button { + background-color: #007bff; + color: white; + border: none; + cursor: pointer; + } + + .Date-filter-form button:hover { + background-color: #0056b3; + } + + .icon-button { + background: none; + border: none; + cursor: pointer; + color: #007bff; + font-size: 18px; + } + + .icon-button:hover { + color: #0056b3; + } + +
+
+
+
+
+

Configuration Details

+
+
+
+
+
+
+ + + + + + + + + +
+
+
+ +
+
+
+ getFlashdata('error'); if ($error) { ?> -
- - getFlashdata('error'); ?> -
- - + + getFlashdata('error'); ?> +
+ + getFlashdata('success'); if ($success) { ?> -
- - getFlashdata('success'); ?> -
- +
+ + getFlashdata('success'); ?> +
+ -
-
- listErrors('
', '
'); +
+
+ listErrors('
', '
'); ?>
-
-
-
-
- - - - - - - - - - - - + +
+
+
Configuration IDConfiguration NameDescriptionCreate DateAction
+ + + + + + + + + + + - - - - - - - - - - CreatedDate)) == "30-11--0001") { + + CreatedDate)) == "30-11--0001") { $cdate = '00-00-0000'; } else { $cdate = date('d-m-Y', strtotime($record->CreatedDate)); } ?> - + + + + + - + - -     + + + + + - -
Create DateConfiguration IDConfiguration NameDescriptionAction
Config_ID ?>ConfigName ?>Comments ?>
Config_ID ?>ConfigName ?>Comments ?>     - -
-
+ +
- - - - - + + + + + + - - + + \ No newline at end of file diff --git a/app/Views/costListing.php b/app/Views/costListing.php index 9bb0564d..565966f0 100644 --- a/app/Views/costListing.php +++ b/app/Views/costListing.php @@ -1,4 +1,35 @@ -
+ +
@@ -8,19 +39,31 @@
-
-
- Add New Cost List +
+
+ + + + + + + + + +
+
+
+ +
- @@ -33,16 +76,13 @@ CreatedDate); $date = $createdat->format('d-m-Y'); $time = $createdat->format('h:i A'); ?> - - + @@ -123,22 +163,22 @@ + \ No newline at end of file diff --git a/app/Views/departmentListing.php b/app/Views/departmentListing.php index d4f6215c..33525d93 100644 --- a/app/Views/departmentListing.php +++ b/app/Views/departmentListing.php @@ -1,104 +1,164 @@ +
- - -
+ + +
-
- getFlashdata('error'); - if ($error) { - ?> -
- - getFlashdata('error'); ?> -
- - getFlashdata('success'); - if ($success) { - ?> -
- - getFlashdata('success'); ?> -
- +
+ getFlashdata('error'); + if ($error) { + ?> +
+ + getFlashdata('error'); ?> +
+ + getFlashdata('success'); + if ($success) { + ?> +
+ + getFlashdata('success'); ?> +
+ -
-
- listErrors('
', '
'); - ?>
-
-
+
+
+ listErrors('
', '
'); + ?>
-
-
-

Department Details

+
+
+
+
+
+

Department Details

+
-
-
+
+
-
-
- +
+
+
+ + + + + + + + + +
+ +
+ +
-
- -
Create Date Create Time Cost Center Code
CreatedDate ?> code ?> CostCenterName ?>
- +
+
+ + + + + + + + + + + + - - - - - + + CreatedDt)) == "30-11--0001") { + $cdate = '00-00-0000'; + } else { + $cdate = date('d-m-Y', strtotime($record->CreatedDt)); + } ?> + + + + + + - - - - - - - - - - - - - - -
Create DateDepartment CodeDepartment NameHead DepartmentIsActive
Department CodeDepartment NameHead DepartmentIsActive DEPCode; ?>DepartmentName ?>HeadDept ?>IsActive == 1) { + echo "Active"; + } else { + echo "In Active"; + } ?>
DEPCode; ?>DepartmentName ?>HeadDept ?>IsActive == 1){echo "Active";} - else { echo "In Active";} ?>
- -
+ + + +
+ +
- - - + + + - --> + \ No newline at end of file diff --git a/app/Views/editEmployee.php b/app/Views/editEmployee.php index 9b4994a7..85145b28 100644 --- a/app/Views/editEmployee.php +++ b/app/Views/editEmployee.php @@ -500,7 +500,7 @@ function validatePF() { if (PF != '') { if (regpf.test(PF) == false) { - alert('Please Enter Valid PF Number'); + alert('Please Enter Valid UAN'); return (false); } else { return true; @@ -1039,31 +1039,26 @@ legend { -
Additional Qualification + -
Referred By + -
Referrer Contact Number + -
-
- -
- -
Work LocationWork Location* -
+
@@ -1100,6 +1095,12 @@ legend {
+
+ + +
+ +
Bank Details @@ -1301,7 +1302,7 @@ legend {
-
PF Number +
UAN SNo Requisition No Item Code - Item Description + Item Name Quantity UOM Rate @@ -1331,7 +1331,7 @@ foreach ($PaymentTerms as $TER) { ReqNo ?> MaterialCode ?> - ServiceMaterialDescription ?> + MaterialName ?> Quantity ?> UOM ?> Rate ?> @@ -1755,7 +1755,7 @@ foreach ($PaymentTerms as $TER) { var cellval = tr.cells; cellval[2].innerHTML = editMaterialCode; - cellval[3].innerHTML = materialspecialinstruction; + cellval[3].innerHTML = editDescription; cellval[4].innerHTML = editQuantity; cellval[5].innerHTML = editUOM; cellval[6].innerHTML = parseFloat(itemRate).toFixed(2); diff --git a/app/Views/employeeListing.php b/app/Views/employeeListing.php index 9663122d..5ce3392d 100644 --- a/app/Views/employeeListing.php +++ b/app/Views/employeeListing.php @@ -1,112 +1,174 @@
- +
-
-
+
+
getFlashdata('error'); - if($error){ + helper('form'); + $error = session()->getFlashdata('error'); + if ($error) { $type = "error"; echo show_alert($type, $error); } $success = session()->getFlashdata('success'); - if($success){ + if ($success) { $type = "success"; echo show_alert($type, $success); } - ?> + ?> -
-
- listErrors('
', '
'); - ?>
-
-
-
-
-
-

Employee Details

-
-
-
-
-
- Add New Employee - Export Employee Details +
+
+ listErrors('
', '
'); + ?>
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - -
Emp IDEmployee NameContact NumberDesignationDepartmentActive
EmpID ?> FirstName; ?>ContactNumber ?>Designation ?>DepartmentName ?>IsActive == 1)? ' Active ' : ' In Active ' ; ?>
- - - +
+
+
+
+

Employee Details

+
+
+
+
+
+
+ + + + + + + + + +
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + Created_date)) == "30-11--0001") { + $cdate = '00-00-0000'; + } else { + $cdate = date('d-m-Y', strtotime($record->Created_date)); + } ?> + + + + + + + + + + +
Created DateEmp IDEmployee NameContact NumberDesignationDepartmentActive
EmpID ?> FirstName; ?>ContactNumber ?>Designation ?>DepartmentName ?>IsActive == 1) ? ' Active ' : ' In Active '; ?>
+ + + +
+
-
-
- --> + \ No newline at end of file diff --git a/app/Views/includes/header.php b/app/Views/includes/header.php index f1925087..45372e2a 100644 --- a/app/Views/includes/header.php +++ b/app/Views/includes/header.php @@ -341,13 +341,18 @@
  • - + + Sales Dashboard
  • - +
  • + + Sales + +
  • diff --git a/app/Views/includes/new_footer.php b/app/Views/includes/new_footer.php index 5ea20056..05486071 100644 --- a/app/Views/includes/new_footer.php +++ b/app/Views/includes/new_footer.php @@ -4,11 +4,26 @@ - - + +
    + +
    +
    +
    + RESICO Version 2.0 | . +
    +
    + +
    +
    +
    +
    +
    - +
    diff --git a/app/Views/includes/new_header.php b/app/Views/includes/new_header.php index a3f8f330..9f002434 100644 --- a/app/Views/includes/new_header.php +++ b/app/Views/includes/new_header.php @@ -2,13 +2,13 @@ - RI + <?php echo $pageTitle; ?> - + @@ -43,294 +43,29 @@ @@ -373,10 +103,10 @@
    @@ -399,151 +129,6 @@ - - - -
    @@ -559,306 +144,127 @@ + + + + + + - - - - - + diff --git a/app/Views/inwardgateregister.php b/app/Views/inwardgateregister.php index f9d9a4bb..abcfaf57 100755 --- a/app/Views/inwardgateregister.php +++ b/app/Views/inwardgateregister.php @@ -10,10 +10,49 @@ text-align: left; } + + - - - + + + - - \ No newline at end of file + $(function() { + + $('#Items').DataTable({ + "paging": false, + "lengthChange": true, + "searching": false, + "ordering": false, + "info": false, + "autoWidth": false + + }); + + $.fn.dataTable.moment('DD-MM-YYYY'); + // $('#Requisition').DataTable({ + // columnDefs: [{ width: 200}], + // fixedColumns: true, + // paging: true, + // lengthChange: true, + // searching: true, + // ordering: true, + // aaSorting: [[ 0, "desc" ]], + + // info: true, + // autoWidth: true, + // pageLength: 10, + // lengthMenu: [10, 25, 50, 100] + + + // }); + }); + + + + + + + + + + + \ No newline at end of file diff --git a/app/Views/rawmaterialListing.php b/app/Views/rawmaterialListing.php index d01ad659..c354edc5 100644 --- a/app/Views/rawmaterialListing.php +++ b/app/Views/rawmaterialListing.php @@ -1,96 +1,148 @@ - -
    -
    -
    - getFlashdata('error'); - if($error){ - $type = "error"; - echo show_alert($type, $error); - } - $success = session()->getFlashdata('success'); - if($success){ - $type = "success"; - echo show_alert($type, $success); - } - ?> + +
    +
    +
    + getFlashdata('error'); + if ($error) { + $type = "error"; + echo show_alert($type, $error); + } + $success = session()->getFlashdata('success'); + if ($success) { + $type = "success"; + echo show_alert($type, $success); + } + ?> + +
    +
    + listErrors('
    ', '
    '); + ?>
    +
    -
    -
    -
    -

    Material Master Details

    -
    -
    +
    +
    +
    +
    +
    +

    Material Master Details

    +
    +
    +
    -
    - +
    +
    + + + + + + + + + +
    +
    +
    +
    -
    - - +
    +
    + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + CreatedDate)) == "30-11--0001") { + $cdate = '00-00-0000'; + } else { + $cdate = date('d-m-Y', strtotime($record->CreatedDate)); + } ?> + + - stock != null || ''){?> - - - - + stock != null || '') { ?> + + + + - + - - -
    Created DateMaterial CodeMaterial DescriptionType of MaterialUOMOpening StockMaterial CategoryHSN Code
    Created OnMaterial CodeMaterial DescriptionType of MaterialUOMOpening StockMaterial CategoryHSN Code
    CreatedDate; ?>CreatedDate,0,'d/m/Y') ?>MaterialCode ?> MaterialCode ?> MaterialName ?> MaterialType ?> UOM ?>stock?>0stock ?>0 Category ?>HSNCODE ?>HSNCODE ?>
    -
    + + + +
    -
    -
    -
    +
    +
    +
    - --> + \ No newline at end of file diff --git a/app/Views/sales_dashboard.php b/app/Views/sales_dashboard.php new file mode 100644 index 00000000..769b578f --- /dev/null +++ b/app/Views/sales_dashboard.php @@ -0,0 +1,23 @@ + + +
    + +
    +

    Sales Dashboard

    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    diff --git a/app/Views/sales_invoice.php b/app/Views/sales_invoice.php new file mode 100644 index 00000000..5b82f841 --- /dev/null +++ b/app/Views/sales_invoice.php @@ -0,0 +1,424 @@ + + +
    + +
    +

    +
    Sales Invoice
    +

    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    + + + + + + + + + + + + + + + + + + + + item_price * $invoice->item_quantity; + // Calculate CGST and SGST + $cgst_amount = ($subtotal * $invoice->cgst) / 100; + $sgst_amount = ($subtotal * $invoice->sgst) / 100; + $total = $subtotal + $cgst_amount + $sgst_amount;?> + + + + + + + + + + + + + + + + + +
    Invoice DateInvoice NoClient NameProductRateQuantitySub TotalGSTTotalStatusE-Invoice NumberAction
    invoice_date_created)); ?> + invoice_url)){ ?> + + + invoice_number; ?> + invoice_url)){ ?> + + + client_name ?>item_name ?>item_price ?>item_quantity, 2 ,'.', ',' ) ?>status ?>e_invoice_number; ?> + + + +
    +
    + +
    +
    +
    +
    +
    + + + + + + + + + + + diff --git a/app/Views/servicePurchaseorder.php b/app/Views/servicePurchaseorder.php index b6df14e9..edb0f790 100644 --- a/app/Views/servicePurchaseorder.php +++ b/app/Views/servicePurchaseorder.php @@ -1,9 +1,9 @@ "NO", "value" => "0"), array("name" => "YES", "value" => "1") + array("name" => "NO", "value" => "0"), + array("name" => "YES", "value" => "1") ); - $ReqType = ''; $CompanyAddress = ''; $dt = new DateTime('now', new DateTimeZone('Asia/Kolkata')); @@ -26,9 +26,7 @@ if (!empty($AvlBudAmt)) { $AvlAmount = number_format($AvlBudAmt, 2, '.', ''); } - if (!empty($INRSYMBOL)) { - foreach ($INRSYMBOL as $INRS) { $INRSYM = $INRS->FontCode2000; } @@ -94,9 +92,6 @@ if (!empty($INRSYMBOL)) { yearRange: '0:+10' }); - - - $('#PoTypeOptions').change(function() { var potypeval = $('#PoTypeOptions').val(); var poopt = ; @@ -118,10 +113,6 @@ if (!empty($INRSYMBOL)) { } }); - - - - document.getElementById("Date").checked = true; $('#drpSupplier').change(function() { @@ -188,7 +179,6 @@ if (!empty($INRSYMBOL)) { $('#ReqNo').change(function() { - var id = $('#ReqNo').val(); $("#AvlBudAmt").val(''); @@ -510,7 +500,6 @@ if (!empty($INRSYMBOL)) { $('#EditTotalOrderValue').val(parseFloat(TotAmt).toFixed(2)); - } function calculateTaxValue() { @@ -628,16 +617,15 @@ if (!empty($INRSYMBOL)) {
    'form-label-left ServicePO ', 'name' => 'ServicePO', 'id' => 'ServicePO', 'enctype' => 'multipart/form-data'); - echo form_open(base_url() . '/purchaseorder/addPO/', $attributes); ?>
    -
    +

    Service Purchase Order

    Back -
    +
    @@ -658,7 +646,7 @@ if (!empty($INRSYMBOL)) { ?> -
    +
    @@ -668,7 +656,7 @@ if (!empty($INRSYMBOL)) { echo form_input($data); ?>
    -
    +
    @@ -686,7 +674,7 @@ if (!empty($INRSYMBOL)) { ?> -
    +
    @@ -695,9 +683,9 @@ if (!empty($INRSYMBOL)) { echo Form_textarea($data); ?>
    -
    -
    -
    +
    + +
    @@ -756,7 +744,7 @@ if (!empty($INRSYMBOL)) {
    - +
    @@ -800,7 +788,7 @@ if (!empty($INRSYMBOL)) {
    -
    +
    @@ -855,7 +843,7 @@ if (!empty($INRSYMBOL)) {
    -
    +
    @@ -902,601 +890,576 @@ if (!empty($INRSYMBOL)) {
    -
    +
    -
    - -
    -
    + +
    + + + + 'txtSpcialInstruction', 'value' => set_value('txtSpcialInstruction'), 'id' => 'txtSpcialInstruction', 'class' => 'form-control', 'rows' => '3', 'cols' => '40'); + echo form_textarea($data); ?> + +
    + + + +
    + + + + + + + + +
    @@ -1505,7 +1468,7 @@ if (!empty($INRSYMBOL)) { - + @@ -1515,14 +1478,12 @@ if (!empty($INRSYMBOL)) { - - -
    SNo Requisition No Item CodeItem DescriptionItem Name Quantity UOM Rate Action
    -
    + + + -
    @@ -1532,31 +1493,28 @@ if (!empty($INRSYMBOL)) { $data = array('name' => 'txtTotBasicAmount', 'value' => set_value('txtTotBasicAmount'), 'id' => 'txtTotBasicAmount', 'class' => 'form-control num', 'readonly' => 'true'); echo form_input($data); ?> -
    +
    'txtTotCgst', 'value' => set_value('txtTotCgst'), 'id' => 'txtTotCgst', 'class' => 'form-control num', 'readonly' => 'true'); echo form_input($data); ?> -
    - - +
    'txtTotSgst', 'value' => set_value('txtTotSgst'), 'id' => 'txtTotSgst', 'class' => 'form-control num', 'readonly' => 'true'); echo form_input($data); ?> -
    +
    'txtTotIgst', 'value' => set_value('txtTotIgst'), 'id' => 'txtTotIgst', 'class' => 'form-control num', 'readonly' => 'true'); echo form_input($data); ?> -
    - +
    -
    +
    -
    - - + +
    @@ -1582,19 +1539,18 @@ if (!empty($INRSYMBOL)) { $data = array('name' => 'descofpo', 'value' => set_value('descofpo'), 'id' => 'descofpo', 'class' => 'form-control', 'rows' => '3', 'cols' => '40'); echo form_textarea($data); ?> -
    -
    + +
    'ScopeOfWork', 'value' => set_value('ScopeOfWork'), 'id' => 'ScopeOfWork', 'class' => 'form-control', 'rows' => '10', 'cols' => '40'); echo form_textarea($data); ?> -
    - -
    + +
    -
    +

    @@ -1608,19 +1564,15 @@ if (!empty($INRSYMBOL)) {   Reset   Save as Draft   Submit -
    -

    -
    - -
    - - - - - - - - + +
    + + + + + + + - + + + +
    +
    +
    +

    Supplier Listing

    +
    +
    +
    +
    +
    +
    + + + + + + + + + +
    +
    +
    + +
    +
    + + + + + + + + + + + + + + + + + + + CreatedOn)) == "30-11--0001") { + $cdate = '00-00-0000'; + } else { + $cdate = date('d-m-Y', strtotime($record->CreatedOn)); + } ?> + + + + + + + + + + + + + +
    Created DateSupplier IDSupplier NameAddressContact NumberEmail AddressPANGST NumberPayment Terms
    SupplierID ?>SupplierName ?>Address ?>ContactNumber ?>EmailAddress ?>PAN ?>GSTNO ?>PaymentTerms ?>IsActive == 0) { + echo "Deactived"; + } else { ?> +     + +
    + +
    +
    +
    +
    + +
    + + + \ No newline at end of file diff --git a/app/Views/userListing.php b/app/Views/userListing.php index ab347e3c..99ed5b13 100644 --- a/app/Views/userListing.php +++ b/app/Views/userListing.php @@ -1,138 +1,269 @@ - +
    - +
    -
    -
    - getFlashdata('error'); - if($error){ +
    +
    + getFlashdata('error'); + if ($error) { $type = "error"; echo show_alert($type, $error); } $success = session()->getFlashdata('success'); - if($success){ + if ($success) { $type = "success"; echo show_alert($type, $success); } - ?> + ?> -
    -
    - listErrors('
    ', '
    '); - ?>
    -
    -
    -
    -
    -
    -

    User Listing

    -
    -
    -
    -
    -
    - Add New User +
    +
    + listErrors('
    ', '
    '); + ?>
    -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    User IdUser NameEmailContact NumberDesignationDepartmentRole NameActions
    userId ?>FirstName ?>EmailId ?>ContactNumber ?>Designation ?>DepartmentName ?>role ?> -     - -     -
    - +
    +
    +
    +

    User Listing

    +
    +
    +
    +
    +
    +
    + + + + + + + + + +
    +
    +
    +
    + +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + createdDtm)) == "30-11--0001") { + $cdate = '00-00-0000'; + } else { + $cdate = date('d-m-Y', strtotime($record->createdDtm)); + } ?> + + + + + + + + + + + + +
    Created DateUser NameEmailContact NumberDesignationDepartmentRole NameActions
    FirstName ?>EmailId ?>ContactNumber ?>Designation ?>DepartmentName ?>role ?> +     + +     +
    + +
    +
    -
    -
    + // $(function () { + // $('#datatable').DataTable({ + // "paging": true, + // "lengthChange": true, + // "searching": true, + // "ordering": true, + // "info": true, + // "autoWidth": true + + // }); + // }); + + + + function deleteUser(userid) { + var answer = confirm(" Do you want to delete the user from the List?") + if (answer) { + $.ajax({ + data: { + id: userid + }, + type: "POST", + url: "user/deleteUser", + success: function(data) { + if (data) { + $('#content').loader('hide'); + alert(data); + + location.reload(); + + + } else { + alert("Error"); + } + + } + }); + } + } + + \ No newline at end of file diff --git a/app/Views/viewinwardgateregister.php b/app/Views/viewinwardgateregister.php index 9385c0a0..c6d022da 100644 --- a/app/Views/viewinwardgateregister.php +++ b/app/Views/viewinwardgateregister.php @@ -48,6 +48,29 @@ white-space: nowrap; } + - + + +

    @@ -91,7 +152,6 @@ - @@ -116,7 +176,6 @@ $time = $createddate->format('h:i A'); ?> - @@ -184,6 +243,7 @@ echo form_input($data); ?> +
    @@ -197,8 +257,8 @@
    - - 'InvoiceNO','value' => set_value('InvoiceNO'),'id'=>'Invoice_No', 'class' => 'form-control', 'required=>"true"' , 'readonly'=>'true' ); + + 'InvoiceNO','value' => set_value('InvoiceNO'),'id'=>'Invoice_No', 'class' => 'form-control', 'required=>"true"' ); echo form_input($data); ?>
    @@ -218,19 +278,26 @@
    -
    +
    'VehicleNo','value' => set_value('VehicleNo'),'id'=>'Vehicle_No', 'class' => 'form-control'); echo form_input($data); ?>
    -
    +
    + + 'Vehicle Type',"Rented"=>'Rented',"Owned"=>'Owned'); + echo form_dropdown('VehicleType', $opt,set_value('VehicleType'),'id="Vehicle_Type"' ,'class="form-control select2'); + ?> +
    +
    'DriverName','value' => set_value('DriverName'),'id'=>'Driver_Name', 'class' => 'form-control'); echo form_input($data); ?>
    -
    +
    'DriverMobileNumber','value' => set_value('DriverMobileNumber'),'id'=>'DriverMobileNumber', 'class' => 'form-control'); echo form_input($data); @@ -292,8 +359,8 @@
    @@ -522,6 +589,7 @@ var invoiceDateInput = modal.find('#Invoice_Date'); var MaterialRcvdDateInput = modal.find('#MaterialRcvdDate'); var VehicleNoInput = modal.find('#Vehicle_No'); + var VehicleTypeInput = modal.find('#Vehicle_Type'); var DriverInput = modal.find('#Driver_Name'); var DriverMobileNumberInput = modal.find('#DriverMobileNumber'); var MasterFileInput = modal.find('#MasterFile'); @@ -579,6 +647,7 @@ console.log(parsedData); $('#printLink').attr('href', '#'); $('.help-block').text(''); $("#Vehicle_No").val(''); + $("#Vehicle_Type").val(''); $("#Driver_Name").val(''); $("#DriverMobileNumber").val(''); $("#IGRStatus").val(''); @@ -608,11 +677,16 @@ console.log(parsedData); var baseUrl = 'purchaseorder/CreatePOPrint'; var newUrl = baseUrl + '?PONO=' + item.PONO + '&ReqType=' + item.POType; $('#printLink').attr('href', newUrl); - var isOpenOrder = parseInt(item.IsOpenOrder, 2); + var isOpenOrder = parseInt(item.IsOpenOrder ? item.IsOpenOrder : "0", 2); + console.log(item.IsOpenOrder); + console.log(isOpenOrder); var formatted_IsOpenOrder = (isOpenOrder === 0 || isNaN(isOpenOrder)) ? "" : "Open"; $('.help-block').text(formatted_IsOpenOrder); - + var button_text_for_IGRDraft= (isOpenOrder === 0 || isNaN(isOpenOrder)) ? "Save as Draft IGR" : "Save as Open IGR"; + $('#draftIGR').text(button_text_for_IGRDraft); + $("#hiddenIsOpenOrder").val(isOpenOrder); $("#Vehicle_No").val(item.VehicleNo); + $("#Vehicle_Type").val(item.VehicleType); $("#Driver_Name").val(item.DriverName); $("#DriverMobileNumber").val(item.DriverMobileNumber); $("#IGRStatus").val(item.IGRStatus); @@ -655,8 +729,8 @@ console.log(parsedData); '
    ' + '' + '' + - '' + - '' + + '' + + '' + '' + '' + '' + @@ -768,10 +842,12 @@ console.log(parsedData); formData.append('mrc', $("#MaterialRcvdDate").val()); formData.append('invdate', $("#Invoice_Date").val()); formData.append('vehicle_no', $('#Vehicle_No').val()); + formData.append('vehicle_type', $('#Vehicle_Type').val()); formData.append('driver', $('#Driver_Name').val()); formData.append('driver_mobile', $('#DriverMobileNumber').val()); formData.append('status', status); formData.append('tableData', JSON.stringify(tableData)); + formData.append('isOpenOrder', $("#hiddenIsOpenOrder").val()); formData.append('MasterFile', $('#MasterFile')[0].files[0]); formData.append('file_name[]', $('#file_name').val()); var empFiles = $('#emp_file')[0] ? $('#emp_file')[0].files : null; @@ -825,10 +901,12 @@ console.log(parsedData); formData.append('mrc', $("#MaterialRcvdDate").val()); formData.append('invdate', $("#Invoice_Date").val()); formData.append('vehicle_no', $('#Vehicle_No').val()); + formData.append('vehicle_type', $('#Vehicle_Type').val()); formData.append('driver', $('#Driver_Name').val()); formData.append('driver_mobile', $('#DriverMobileNumber').val()); formData.append('status', status); formData.append('tableData', JSON.stringify(tableData)); + formData.append('isOpenOrder',$("#hiddenIsOpenOrder").val()); formData.append('MasterFile', $('#MasterFile')[0].files[0]); formData.append('file_name[]', $('#file_name').val()); var empFiles = $('#emp_file')[0] ? $('#emp_file')[0].files : null; @@ -1376,32 +1454,39 @@ function deleteBill(Billno,i){ } } - function validateReceivedQuantity(Rowid) { + function validateReceivedQuantity(Rowid,isOpenOrder) { var InvoiceQty = parseFloat($('#QuantityAsPerInvoice' + Rowid).val() || '0.00'); // working fine var OrderedQty = parseFloat($("#Quantity" + Rowid).text()); - - if (parseInt(OrderedQty) !== 0) { - if ((InvoiceQty) > OrderedQty) { - alert("Pending Quantity is exceeding the Ordered Quantity. Please contact the Purchase Team for further process."); - $("#QuantityAsPerInvoice" + Rowid).focus().val(''); - return false; - } else if ((InvoiceQty) - OrderedQty > 0.00) { - alert("Order is completed."); - $("#QuantityAsPerInvoice" + Rowid).focus().val(''); - return false; - } else { - var PendingQty = OrderedQty - (InvoiceQty); - $('#PendingQuantity' + Rowid).text(PendingQty.toFixed(0)); - $('#txtPendingQty' + Rowid).val(PendingQty.toFixed(0)); - $('#txtQuantityAsPerInvoice' + Rowid).val(InvoiceQty.toFixed(2)); - return true; - } - } else { - var PendingQty = OrderedQty - (InvoiceQty); + if(isOpenOrder == 1){ + var PendingQty = 0; $('#PendingQuantity' + Rowid).text(PendingQty.toFixed(0)); $('#txtPendingQty' + Rowid).val(PendingQty.toFixed(0)); $('#txtQuantityAsPerInvoice' + Rowid).val(InvoiceQty.toFixed(2)); return true; + }else{ + if (parseInt(OrderedQty) !== 0) { + if ((InvoiceQty) > OrderedQty) { + alert("Pending Quantity is exceeding the Ordered Quantity. Please contact the Purchase Team for further process."); + $("#QuantityAsPerInvoice" + Rowid).focus().val(''); + return false; + } else if ((InvoiceQty) - OrderedQty > 0.00) { + alert("Order is completed."); + $("#QuantityAsPerInvoice" + Rowid).focus().val(''); + return false; + } else { + var PendingQty = OrderedQty - (InvoiceQty); + $('#PendingQuantity' + Rowid).text(PendingQty.toFixed(0)); + $('#txtPendingQty' + Rowid).val(PendingQty.toFixed(0)); + $('#txtQuantityAsPerInvoice' + Rowid).val(InvoiceQty.toFixed(2)); + return true; + } + } else { + var PendingQty = OrderedQty - (InvoiceQty); + $('#PendingQuantity' + Rowid).text(PendingQty.toFixed(0)); + $('#txtPendingQty' + Rowid).val(PendingQty.toFixed(0)); + $('#txtQuantityAsPerInvoice' + Rowid).val(InvoiceQty.toFixed(2)); + return true; + } } } @@ -1524,8 +1609,20 @@ function deleteBill(Billno,i){ + + + + + + + +
    Create Date Create time IGR No
    CreatedDate ?> IGRNO ?> ' + item.MaterialName + '' + item.UOM + '' + parseInt(item.Quantity) + '' + parseInt(item.Quantity - item.QuantityAsPerInvoice) + '' + ((isOpenOrder) ? 0 : parseInt(item.Quantity - item.QuantityAsPerInvoice)) + '