403Webshell
Server IP : 103.234.187.230  /  Your IP : 216.73.216.216
Web Server : Apache
System : Linux lserver42043-ind.megavelocity.net 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/b2bzend/application/modules/finance/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/b2bzend/application/modules/finance/controllers/SupplierController.php
<?php

class Finance_SupplierController extends Catabatic_ValidateGtx {

    public function init() {
        parent::init();
        $this->db = Zend_Db_Table::getDefaultAdapter();
        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        $this->intLoggedinUserAgencySysId = $sessionLogin_user->intLoggedinUserAgencySysId;
        $this->intLoggedinUserId = $sessionLogin_user->intLoggedinUserId;
        $this->agencyDetails = $sessionLogin_user->agencyDetails;
        $this->IsSMSApi = $sessionLogin_user->agencyDetails['IsSMSApi'];
        $this->SENDREGISTERSMSCONFIG = Catabatic_Helper::getSENDREGISTERSMSCONFIG();
        if ($sessionLogin_user->IsSuperAdmin == True || $sessionLogin_user->IsAdmin == True) {
            $this->IsAdmin = true;
        } else {
            $this->IsAdmin = false;
        }
        $this->_crmcusttravelplan = new Travel_Model_CRM_CustomerTravelPlan();
        $this->view->IsAdmin = $this->IsAdmin;
    }

    public function indexAction() {
        $objAgency = new Travel_Model_TblAgency();
        $MasterAgencySysId = $this->intLoggedinUserAgencySysId;
        $getData = $this->getRequest()->getPost();
        $SupplierSysId = $this->_request->getParam('ssid', NULL);
        if ($getData) {
            $this->_HtmlPurifier = new Zend_Filter_HtmlPurifier();
            $FromDate = $this->_request->getParam('from_date', NULL);
            $ToDate = $this->_request->getParam('to_date', NULL);
            if ($FromDate != NULL && $ToDate != NULL) {
                $ExToDate = explode('-', $ToDate);
                $NToDate = $ExToDate['2'] . '-' . $ExToDate['1'] . '-' . $ExToDate['0'];
                $ExFromDate = explode('-', $FromDate);
                $NFromDate = $ExFromDate['2'] . '-' . $ExFromDate['1'] . '-' . $ExFromDate['0'];
                $getData['ToDate'] = $NToDate;
                $getData['FromDate'] = $NFromDate;
            }
            $getData = $this->_HtmlPurifier->filterArray($getData);
        }
        $this->view->searchData = $getData;
        $getData['IsApproved'] = 1;
        $SupplierList = $objAgency->getAgencySuppliers($MasterAgencySysId, $SupplierSysId);
        $page = $this->_getParam('page', 1);
        $paginator = Zend_Paginator::factory($SupplierList);
        $paginator->setItemCountPerPage(GRID_PER_PAGE_RECORD_COUNT);
        $paginator->setCurrentPageNumber($page);
        $this->view->paginator = $paginator;
        $msg = $this->_getParam('msg');
        $this->view->msg = $msg;
        $this->view->openpopup = $this->_request->getParam('op', null);
        $this->view->controller = $this;
        $this->view->messages = $this->_helper->flashMessenger->getMessages();
    }

    public function flightDetailsAction() {
        $objProcedures = new Gtxwebservices_Model_Procedures();
        $AgencySysId = $this->intLoggedinUserAgencySysId;
        $getData = array();
        if ($this->getRequest()->isPost()) {
            $getData = $this->getRequest()->getPost();
            if (!empty($getData)) {
                if ($getData['supplierName'] != '') {
                    $supplierName = isset($getData['supplierName']) ? trim($getData['supplierName']) : '';
                }
            }
        }
        $monthFrom = $this->getRequest()->getPost('monthFrom', "");
        $yearFrom = $this->getRequest()->getPost('yearFrom', "");
        $dateFrom = $this->getRequest()->getPost('dateFrom', "");
        $dateTo = $this->getRequest()->getPost('dateTo', "");
        $resultSet = $objProcedures->getFlightBookingSupplierWise($AgencySysId, $monthFrom, $yearFrom, $dateFrom, $dateTo);
        $this->view->trxData = $resultSet;
        $this->view->getData = $getData;
        $this->view->supplierName = $supplierName;
    }

    public function creditLimitAction() {
        $objAgency = new Travel_Model_TblAgency();
        $TblCurrency = new Travel_Model_TblCurrency();
        $this->view->layout()->disableLayout();
        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        $MasterAgencySysId = $this->intLoggedinUserAgencySysId;
        $getPaymentMode = $objAgency->getAllPaymentMode();
        $this->view->getPaymentMode = $getPaymentMode;
        $this->view->ContactNo1 = $sessionLogin_user->agencyDetails['ContactInfo'];
        $this->view->SupplierSysId = $SupplierSysId = ($this->getRequest()->getParam('aid')) ? base64_decode($this->getRequest()->getParam('aid')) : '';
        $this->view->b2bAgencyData = $objAgency->getSupplierDetails($MasterAgencySysId, $SupplierSysId);
        $this->view->CurrencyType = $CurrencyType = $TblCurrency->getCurrencyTypes();
        $this->view->intLoggedinUserTrxCurrency = $intLoggedinUserTrxCurrency = $sessionLogin_user->intLoggedinUserTrxCurrency;
        $this->view->CreditLimitData = $CreditLimitData = $objAgency->getSupplierWalletData($SupplierSysId);
        $this->view->CreditDataHistory = $CreditDataHistory = $objAgency->getAgencyCreditLimitDataBySupplierId($SupplierSysId);
//        echo"<pre>";print_r($CreditDataHistory);die('dd');
        $this->view->getSupplierDetails = $getSupplierDetails = $objAgency->getSupplierDetails($MasterAgencySysId, $SupplierSysId);
        $this->view->frombankDetailsArray = $frombankDetailsArray = $objAgency->getAgencyBankDetails($MasterAgencySysId);
        $this->view->tobankDetailsArray = $tobankDetailsArray = $objAgency->getSupplierBankDetails($MasterAgencySysId, $SupplierSysId);
    }

    public function creditLimitOtpAction() {
        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        $intLoggedinUserId = $sessionLogin_user->intLoggedinUserId;
        if ($this->getRequest()->isPost()) {
            $objPackage = new Travel_Model_TblPackage();
            $param = $this->getRequest()->getParams();
            $data = new Payment_Model_Checkotp();
            $mobile_no = $sessionLogin_user->agencyDetails['ContactInfo'];
            $PrimaryEmail = $EmailId = $sessionLogin_user->agencyDetails['PrimaryEmail'];
            if ($this->intLoggedinUserAgencySysId == 119378) {
                $mobile_no = '8800403973';
                $EmailId = 'finance@dudigitalglobal.com';
            }

            $randomString = $data->randomString();
            $message = "Hi,\nUse $randomString as OTP (One Time Password) to verify your mobile number. Do not share this OTP with anyone for security reason.\nThanks\nTeam HelloGTX\nTRVCRM";
            $this->postFields = "";
            $this->postFields .= "&method=$this->SMSMETHOD";
            $this->postFields .= "&api_key=$this->SMSAPIKEY";
            $this->postFields .= "&to=$mobile_no";
            $this->postFields .= "&sender=$this->SMSSENDER";
            $this->postFields .= "&message=$message";
            $this->postFields .= "&format=$this->SMSFORMAT";
            $postURL = $this->SMSURL;
            $arrSMSStatisticsType = array_keys(unserialize(ARR_SMS_STATISTICS_TYPE));
            $arrSMSStatistics = array(
                "TPSysId" => 0,
                "TypeSysId" => 2, // 1 For Email 2 For SMS
                "AgencySysId" => $this->intLoggedinUserAgencySysId,
                "AgentSysId" => $this->intLoggedinUserId,
                "Title" => $message,
                "Source" => $arrSMSStatisticsType[0], // 2 Resend Proposals (Bulk)
                "Status" => '',
                "RefSysId" => '',
                "RefSysStatus" => "",
                "CreateDate" => date('Y-m-d H:s:i')
            );

            try {
                $updateCreditType = isset($param['updateCreditType']) ? (int) $param['updateCreditType'] : 1;
                if ($updateCreditType == 1) {
                    $resultVal = $data->sendSmsDetails($postURL, $this->postFields, $arrSMSStatistics, $this->IsSMSApi);
                    //$resultVal['status'] = 'OK';
                    $resultVal['message'] = $resultVal['Message'];
                    $PlanType = 7;
                    $PaymentMode = "Reduce Advanced";
                    if (isset($param['TrxType']) && $param['TrxType'] == 1) {
                        $PaymentMode = "Add Advanced";
                    }
                } else {
                    $PlanType = 7;
                    $resultVal = $data->sendSmsDetails($postURL, $this->postFields, $arrSMSStatistics, $this->IsSMSApi);
                    // $resultVal['status'] = 'OK';

                    $resultVal['message'] = $resultVal['Message'];
                    $PaymentMode = "Reduce Advanced";
                    if (isset($param['TrxType']) && $param['TrxType'] == 1) {
                        $PaymentMode = "Add Advanced";
                    }
                }
                $subject = "OTP for " . $PaymentMode;
                $html = new Zend_View();
                $html->setScriptPath(APPLICATION_PATH . '/views/emails/');
                $html->assign(array('randomString' => $randomString, 'agencyDetails' => $sessionLogin_user->agencyDetails, 'PaymentMode' => $PaymentMode));
                $bodyText = $html->render('OTPEmailMaster.phtml');
                $DisplayName = $sessionLogin_user->agencyDetails['DisplayName'];
                $emailData = array('fromEmail' => $PrimaryEmail, 'fromName' => $DisplayName, 'subject' => $subject, 'to' => array($EmailId), 'bodyHtml' => $bodyText, 'bodyText' => '');
                $arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
                $arrEmailStatistics = array(
                    "TPSysId" => 0,
                    "TypeSysId" => 1, // 1 For Email 2 For SMS
                    "AgencySysId" => $this->intLoggedinUserAgencySysId,
                    "AgentSysId" => $this->intLoggedinUserId,
                    "Title" => $message,
                    "Source" => $arrEmailStatisticsType[2], // 6 For Misc
                    "Status" => 0,
                    "RefSysId" => "",
                    "RefSysStatus" => "",
                    "CreateDate" => date('Y-m-d H:s:i')
                );
                $resultmail = $this->mailSentByElastice($emailData, $arrEmailStatistics);
                $WalletId = $param['WalletId'];

//                if (trim($resultVal['status']) == 'OK') {
                if (isset($param['mode']) && ($param['mode'] == 'edit') && ($WalletId)) {
//                    if (($WalletId)) {
                    $updateData = [
                        'SupplierSysId' => $param['SupplierSysId'],
                        'UpdateDate' => date('Y-m-d H:i:s'),
                        'IsMarkForDel' => 0,
                        'IsActive' => 1,
//                            'CurrencyType' => isset($param['CurrencyType']) ? $param['CurrencyType'] : 1,
//                            'BalanceAmount' => $param['CreditAmount'],
                    ];
                    $whereQuery1 = array('WalletId = ? ' => $WalletId, 'SupplierSysId = ? ' => $param['SupplierSysId']);
                    $objPackage->updateData('TB_Supplier_Wallet', $updateData, $whereQuery1);
                    $saveHistoryData = [
                        'SupplierId' => $param['SupplierSysId'],
                        'WalletId' => $WalletId,
                        'ReferenceType' => $PaymentMode,
                        'PaymentMode' => isset($param['offlinePaymentMode']) ? $param['offlinePaymentMode'] : '',
                        'CurrencyType' => isset($param['CurrencyType']) ? $param['CurrencyType'] : 1,
                        'TotalAmount' => $param['CreditAmount'],
                        'PaidAmount' => $param['CreditAmount'],
                        'Remarks' => $param['Remark'],
                        'OTPCode' => $randomString,
                        'CodeValidFrom' => date('Y-m-d H:i'),
                        'CodeValidTo' => date('Y-m-d H:i', (strtotime(date('Y-m-d H:i')) + 600)),
                        'CreateDate' => date('Y-m-d H:i'),
                        'UpdateDate' => date('Y-m-d H:i:s'),
                        'IsApproved' => 0,
                        'AgentSysId' => $intLoggedinUserId,
                        'GSTInput' => 0,
                        'TransactionReference' => isset($param['ReferenceNo']) ? $param['ReferenceNo'] : '',
                        'ToAccount' => isset($param['ToAccount']) ? $param['ToAccount'] : 0,
                        'FromAccount' => isset($param['FromAccount']) ? $param['FromAccount'] : 0,
                        'TransactionDate' => date('Y-m-d'),
                        'Balance' => $param['CreditAmount'],
                        'ReferenceId' => 0,
                        'GSTNo' => 0,
                        'IGST' => 0,
                        'SGST' => 0,
                        'CGST' => 0,
                        'OtherCharges' => 0,
                        'BankCharges' => 0,
                        'TransactionType' => $param['TrxType'],
                        'TPSysId' => '',
                        'IsMarkForDel' => 0,
                        'IsActive' => 0
                    ];

                    $TransactionId = $objPackage->insertData('TB_Supplier_Wallet_History', $saveHistoryData);
//                    }
                } else {
                    $saveData = [
                        'SupplierSysId' => $param['SupplierSysId'],
                        'CurrencyType' => isset($param['CurrencyType']) ? $param['CurrencyType'] : 1,
                        'BalanceAmount' => $param['CreditAmount'],
                        'UpdateDate' => date('Y-m-d H:i:s'),
                        'IsMarkForDel' => 0,
                        'IsActive' => 0,
                    ];

                    $WalletId = $objPackage->insertData('TB_Supplier_Wallet', $saveData);

                    $saveHistoryData = [
                        'SupplierId' => $param['SupplierSysId'],
                        'WalletId' => $WalletId,
                        'ReferenceType' => $PaymentMode,
                        'PaymentMode' => isset($param['offlinePaymentMode']) ? $param['offlinePaymentMode'] : '',
                        'CurrencyType' => isset($param['CurrencyType']) ? $param['CurrencyType'] : 1,
                        'TotalAmount' => $param['CreditAmount'],
                        'PaidAmount' => $param['CreditAmount'],
                        'Remarks' => $param['Remark'],
                        'OTPCode' => $randomString,
                        'CodeValidFrom' => date('Y-m-d H:i'),
                        'CodeValidTo' => date('Y-m-d H:i', (strtotime(date('Y-m-d H:i')) + 600)),
                        'CreateDate' => date('Y-m-d H:i'),
                        'UpdateDate' => date('Y-m-d H:i:s'),
                        'AgentSysId' => $intLoggedinUserId,
                        'TransactionReference' => isset($param['ReferenceNo']) ? $param['ReferenceNo'] : '',
                        'ToAccount' => isset($param['ToAccount']) ? $param['ToAccount'] : 0,
                        'FromAccount' => isset($param['FromAccount']) ? $param['FromAccount'] : 0,
                        'TransactionDate' => date('Y-m-d'),
                        'Balance' => $param['CreditAmount'],
                        'ReferenceId' => 0,
                        'GSTInput' => 0,
                        'IsApproved' => 0,
                        'GSTNo' => 0,
                        'IGST' => 0,
                        'SGST' => 0,
                        'CGST' => 0,
                        'OtherCharges' => 0,
                        'BankCharges' => 0,
                        'TransactionType' => $param['TrxType'],
                        'TPSysId' => '',
                        'IsMarkForDel' => 0,
                        'IsActive' => 0
                    ];
                    $TransactionId = $objPackage->insertData('TB_Supplier_Wallet_History', $saveHistoryData);
                }
                $response = array('status' => true, 'msg' => $resultVal['message'], 'WalletId' => $WalletId, 'TransactionId' => $TransactionId, 'otp' => '');
//                } else {
//                    $response = array('status' => false, 'msg' => $resultVal['message']);
//                }
                echo json_encode($response);
                exit;
            } catch (Exception $e) {
                $response = array('status' => false, 'msg' => $e->getMessage());
                echo json_encode($response);
                exit;
            }
        }
    }

    public function viewCreditLimitAction() {
//         error_reporting(E_ALL);
        $objAgency = new Travel_Model_TblAgency();
        $TblCurrency = new Travel_Model_TblCurrency();
        $this->view->aid = $aid = $this->getRequest()->getParam('aid');
        $filterData = array();
        if ($this->getRequest()->isPost()) {
            $filterData = $this->getRequest()->getParams();
            $FromDate = (isset($filterData['FromDate']) && $filterData['FromDate'] != '__/__/____') ? explode('/', $filterData['FromDate']) : '';
            $ToDate = (isset($filterData['ToDate']) && $filterData['ToDate'] != '__/__/____') ? explode('/', $filterData['ToDate']) : '';
            $FromDateN = (!empty($FromDate)) ? trim($FromDate[2] . '-' . $FromDate[1] . '-' . $FromDate[0]) : '';
            $ToDateN = (!empty($ToDate)) ? trim($ToDate[2] . '-' . $ToDate[1] . '-' . $ToDate[0]) : '';
            $objAgency->filterArray = array('FromDate' => $FromDateN, 'ToDate' => $ToDateN);
        }
        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        $MasterAgencySysId = $this->intLoggedinUserAgencySysId;
        $this->view->ContactNo1 = $sessionLogin_user->agencyDetails['ContactInfo'];
        $this->view->SupplierSysId = $SupplierSysId = ($this->getRequest()->getParam('aid')) ? base64_decode($this->getRequest()->getParam('aid')) : '';
        // $this->view->b2bAgencyData = $b2bAgencyData = $objAgency->isB2BAgencyExists('', $AgencySysId, $MasterAgencySysId);
        $this->view->CurrencyType = $CurrencyType = $TblCurrency->getCurrencyTypes();
        $this->view->b2bAgencyData = $objAgency->getSupplierDetails($MasterAgencySysId, $SupplierSysId);
        $this->view->intLoggedinUserTrxCurrency = $intLoggedinUserTrxCurrency = $sessionLogin_user->intLoggedinUserTrxCurrency;
        $this->view->CreditLimitData = $CreditLimitData = $objAgency->getAgencyCreditLimitDataBySupplierId($SupplierSysId);
//        echo"<pre>";print_r($CreditLimitData);die('data');
        $page = $this->_getParam('page', 1);
        $paginator = Zend_Paginator::factory($CreditLimitData);
        $paginator->setItemCountPerPage(GRID_PER_PAGE_RECORD_COUNT);
        $paginator->setCurrentPageNumber($page);
        $this->view->paginator = $paginator;
        $this->view->filterData = $filterData;
    }

    public function saveCreditLimitDataAction() {
        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        $intLoggedinUserId = $sessionLogin_user->intLoggedinUserId;
        if ($this->getRequest()->isPost()) {
            $param = $this->getRequest()->getParams();
            $objPackage = new Travel_Model_TblPackage();
            $objAgency = new Travel_Model_TblAgency();
            $otp = (isset($param['otp']) && !empty($param['otp'])) ? trim($param['otp']) : '';
            $TransactionId = (isset($param['TransactionId']) && !empty($param['TransactionId'])) ? trim($param['TransactionId']) : '';
            $WalletId = (isset($param['WalletId']) && !empty($param['WalletId'])) ? trim($param['WalletId']) : '';
            $SupplierSysId = (isset($param['SupplierSysId']) && !empty($param['SupplierSysId'])) ? trim($param['SupplierSysId']) : '';
            $CreditLimitData = $objAgency->checkSupplierCreditLimitOtp($WalletId, $TransactionId);
            $CodeValidTo = strtotime($CreditLimitData['CodeValidTo']->format('Y-m-d H:i'));
            $currencttime = strtotime(date('Y-m-d H:i'));
            $dt = DateTime::createFromFormat('U.u', microtime(true));
            $dt->setTimezone(new DateTimeZone('Asia/Kolkata'));
            $formatted = $dt->format("Y-m-d H:i:s") . '.' . substr($dt->format("u"), 0, 3);
            $minuts = $currencttime - $CodeValidTo;
            if ($minuts > 10) {
                $response = array('status' => false, 'msg' => 'otp Expired');
                echo json_encode($response);
                exit;
            }
            if ($otp != $CreditLimitData['OTPCode']) {
                $response = array('status' => false, 'msg' => 'Invalid OTP.');
                echo json_encode($response);
                exit;
            }
            if (isset($param['mode']) && $param['mode'] == 'edit') {
                $CreditDate = date('Y-m-d', strtotime(date('Y-m-d') . " +" . $param['CreditDays'] . " days"));
                $CreditAmount = isset($param['CreditAmount']) ? $param['CreditAmount'] : 0;

                if ($WalletId != '' && $TransactionId != '') {
                    if (isset($CreditLimitData['TransactionType']) && (int) $CreditLimitData['TransactionType'] == 1) {
                        $saveData = [
                            'BalanceAmount' => new Zend_Db_Expr("BalanceAmount + $CreditAmount"),
                            'UpdateDate' => date('Y-m-d H:i:s'),
                            'IsMarkForDel' => 0,
                            'IsActive' => 1,
                        ];
                    } else {
                        $saveData = [
                            'BalanceAmount' => new Zend_Db_Expr("BalanceAmount - $CreditAmount"),
                            'UpdateDate' => date('Y-m-d H:i:s'), // Use full timestamp format
                            'IsMarkForDel' => 0,
                            'IsActive' => 1,
                        ];
                    }


                    $whereQuery1 = array('WalletId = ? ' => $WalletId, 'SupplierSysId = ? ' => $SupplierSysId);
                    $objPackage->updateData('TB_Supplier_Wallet', $saveData, $whereQuery1);

                    $BalanceAmountSP = $objAgency->getCreditBalanceSupplier($WalletId, $SupplierSysId);
                    $saveHistoryData = [
                        'AgentSysId' => $intLoggedinUserId,
                        'Balance' => $BalanceAmountSP,
                        'Remarks' => $param['Remark'],
                        'OTPCode' => 0,
                        'CodeValidFrom' => date('Y-m-d H:i'),
                        'CodeValidTo' => date('Y-m-d H:i', (strtotime(date('Y-m-d H:i')) + 600)),
                        'UpdateDate' => $formatted,
                        'IsMarkForDel' => 0,
                        'IsActive' => 1
                    ];

                    $whereQuery2 = array('WalletId = ? ' => $WalletId, 'TransactionId = ? ' => $TransactionId, 'SupplierId = ? ' => $SupplierSysId);
                    $objPackage->updateData('TB_Supplier_Wallet_History', $saveHistoryData, $whereQuery2);
                    $response = array('status' => true, 'msg' => 'success', 'WalletId' => $WalletId, 'TransactionId' => $TransactionId);
                } else {
                    $response = array('status' => false, 'msg' => 'fail', 'WalletId' => $WalletId, 'TransactionId' => $TransactionId);
                }
            } else {
                $CreditDate = date('Y-m-d', strtotime(date('Y-m-d') . " +" . $param['CreditDays'] . " days"));
                $saveData = [
                    'BalanceAmount' => new Zend_Db_Expr("BalanceAmount + $CreditAmount"),
                    'UpdateDate' => date('Y-m-d H:i:s'),
                    'IsMarkForDel' => 0,
                    'IsActive' => 1,
                ];
                $BalanceAmount = $objAgency->getCreditBalanceSupplier($WalletId, $SupplierSysId);
                $saveHistoryData = [
                    'AgentSysId' => $intLoggedinUserId,
                    'Balance' => $BalanceAmount,
                    'Remarks' => $param['Remark'],
                    'OTPCode' => 0,
                    'CodeValidFrom' => date('Y-m-d H:i'),
                    'CodeValidTo' => date('Y-m-d H:i', (strtotime(date('Y-m-d H:i')) + 600)),
                    'UpdateDate' => $formatted,
                    'IsMarkForDel' => 0,
                    'IsActive' => 1
                ];
                if ($WalletId != '' && $TransactionId != '') {
                    $whereQuery1 = array('WalletId = ? ' => $WalletId, 'SupplierSysId = ? ' => $SupplierSysId);
                    $objPackage->updateData('TB_Supplier_Wallet', $saveData, $whereQuery1);
                    $whereQuery2 = array('WalletId = ? ' => $WalletId, 'TransactionId = ? ' => $TransactionId, 'SupplierId = ? ' => $SupplierSysId);
                    $objPackage->updateData('TB_Supplier_Wallet_History', $saveHistoryData, $whereQuery2);
                    $response = array('status' => true, 'msg' => 'success', 'WalletId' => $WalletId, 'TransactionId' => $TransactionId);
                } else {
                    $response = array('status' => false, 'msg' => 'fail', 'WalletId' => $WalletId, 'TransactionId' => $TransactionId);
                }
            }
            echo json_encode($response);
            exit;
        }
    }

    public function manageBillAction() {
//            error_reporting(E_ALL);
        Zend_Session::namespaceUnset('sessionInvoiceData');
        $this->view->intLoggedinUserAgencySysId = $this->intLoggedinUserAgencySysId;
        $ICSourceSysId = $this->intLoggedinUserAgencySysId;
        $objAgency = new Travel_Model_TblAgency();
        $objSupplier = new Travel_Model_TblSupplier();
        $agencyDetails = $objAgency->getAgencyUserList($this->intLoggedinUserAgencySysId);
        $this->view->agencyDetails = $agencyDetails;
        $source = $this->_request->getParam('filter', 'current-month');
        $post = $this->getRequest()->getPost();
        $currentDate = date("Y-m-d");
        $currentMonth = date("m");
        $currentYear = date("Y");
        $fromDate = "$currentYear-$currentMonth-01";

        $this->view->source = $source;
        $this->view->post = $post;
        $supplierBillList = $objSupplier->supplierBillList($ICSourceSysId, $fromDate, $currentDate, $post);
        $page = $this->_getParam('page', 1);
        $paginator = Zend_Paginator::factory($supplierBillList);
        $paginator->setItemCountPerPage(25);
        $paginator->setCurrentPageNumber($page);
        $this->view->paginator = $paginator;
        $this->view->messages = $this->_helper->flashMessenger->getMessages();
    }

    public function addBillAction() {
//        error_reporting(E_ALL);
        $SupplierMdl = new Webservice_Model_Supplier();
        $objVisa = new Travel_Model_TblVisa();
        $modelTBOMdl = new Webservice_Model_TboData();
        $agencyMdl = new Travel_Model_TblAgency();
        $objAgency = new Travel_Model_TblAgency();
        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        $ServiceTaxNo = isset($sessionLogin_user->agencyDetails['ServiceTaxNo']) ? $sessionLogin_user->agencyDetails['ServiceTaxNo'] : '';
        $this->view->proposalid = $proposalid = $this->getRequest()->getParam("proposalid");
        $this->view->supplierid = $supplierid = $this->getRequest()->getParam("supplierid");
        $code = $this->getRequest()->getParam("code");
        $this->view->billId = $billId = ($this->getRequest()->getParam("billId")) ? base64_decode($this->getRequest()->getParam("billId")) : 0;
        $SupplierName = '';
        $this->view->MarketPlace = $objVisa->MarketPlace();
        $this->view->intLoggedinUserAgencySysId = $ICSourceSysId = $this->intLoggedinUserAgencySysId;
        $this->view->SupplierList = $SupplierList = $objAgency->getAgencySuppliers($ICSourceSysId);
        if ($supplierid > 0) {
            $supplierData = $objAgency->getSupplierDetails($ICSourceSysId, $supplierid);
            $SupplierName = $supplierData['SupplierName'];
            $SupplierCurrencyType = $supplierData['CurrencyType'];
            $GstApplicable = $supplierData['GstApplicable'];
            $GSTNo = $supplierData['GSTNo'];
            $gstvalidate = [];
            if ($GstApplicable == 1) {
                $gstvalidate = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->gstvalidate($GSTNo, $ServiceTaxNo);
            }
        }
        $this->view->SupplierName = $SupplierName;
        $this->view->SupplierCurrencyType = $SupplierCurrencyType;
        $this->view->GstApplicable = $GstApplicable;
        $this->view->GSTNo = $GSTNo;
        $this->view->gstvalidate = $gstvalidate;
        $AgentSysId = $this->intLoggedinUserId;
        $AddressAgency = $objAgency->getAddressByAgency($ICSourceSysId);
        $AgencyTnCDetails = $objAgency->getAgencyTnCDetails($ICSourceSysId);
        $getAgencyData = $objAgency->getAgencyData($ICSourceSysId);
        $this->view->PaymentDetails = (isset($AgencyTnCDetails['PaymentDetails']) && !empty($AgencyTnCDetails['PaymentDetails']) ? $AgencyTnCDetails['PaymentDetails'] : '');
        $this->view->PaymentDetailsInvoice = (isset($AgencyTnCDetails['TermConditionsInvoice']) && !empty($AgencyTnCDetails['TermConditionsInvoice']) ? $AgencyTnCDetails['TermConditionsInvoice'] : '');
        $this->view->AddressAgency = $AddressAgency;
        $this->view->ICSourceSysId = $ICSourceSysId;
        $this->view->getAgencyData = $getAgencyData;
        $this->view->MarketPlace = $objVisa->MarketPlace();
        $objCurrency = new Travel_Model_TblCurrency();
        $this->view->arrCurrencyTypes = $objCurrency->getCurrencyTypes();
        $objPackage = new Travel_Model_TblPackage();

        if ($this->getRequest()->isPost()) {
            $request = Zend_Controller_Front::getInstance()->getRequest();
            $post = $request->getPost();
//            echo"<pre>";print_r($post);die('dd');
            $CreateDate = date('Y-m-d H:i:s');
            $SupplierSysId = isset($post['hidden_selected_supplier_sys_id']) ? $post['hidden_selected_supplier_sys_id'] : 0;
            $billId = isset($post['billId']) ? $post['billId'] : '';
            $InvoiceNo = $BillNumber = isset($post['bill_no']) ? $post['bill_no'] : 0;
            $BillDate = isset($post['dateofissue']) ? $post['dateofissue'] : $CreateDate;
            $BillDueDate = isset($post['duedates']) ? $post['duedates'] : '';
            $BillDate = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($BillDate, 'd/m/y');
            $BillDueDate = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($BillDueDate, 'd/m/y');
            $IsITCApplicable = isset($post['client_gst']) ? $post['client_gst'] : 0;
            $IsTDS = isset($post['IsTDS']) ? $post['IsTDS'] : 0;
            $totalITDS = isset($post['totalITDS']) ? $post['totalITDS'] : 0;
            $PanCard = isset($post['PanCard']) ? $post['PanCard'] : 0;
            $CurrencyType = isset($post['Currency']) ? $post['Currency'] : null;
            $totalpayable = isset($post['totalpayable']) ? $post['totalpayable'] : 0;
            $TotalMarkup = isset($post['TotalMarkup']) ? $post['TotalMarkup'] : 0;
            $TotalDiscount = isset($post['Sumdiscount']) ? $post['Sumdiscount'] : 0;
            $TotalTax = isset($post['TotalTax']) ? $post['TotalTax'] : 0;
            $subtotals = isset($post['subtotals']) ? $post['subtotals'] : 0;
            $Remarks = isset($post['Remarks']) ? $post['Remarks'] : '';
            $GstNumber = isset($post['client_gst_no']) ? $post['client_gst_no'] : '';
            $totalCGST = isset($post['totalCGST']) ? $post['totalCGST'] : 0;
            $totalSGST = isset($post['totalSGST']) ? $post['totalSGST'] : 0;
            $totalIGST = isset($post['totalIGST']) ? $post['totalIGST'] : 0;
            $this->view->intLoggedinUserAgencySysId = $AgencySysId = $this->intLoggedinUserAgencySysId;
            $AgentSysId = $this->intLoggedinUserId;

            try {
                $saveData = [
                    'SupplierSysId' => $SupplierSysId,
                    'AgencySysId' => $AgencySysId,
                    'BillNumber' => $BillNumber,
                    'BillDate' => $BillDate,
                    'BillDueDate' => $BillDueDate,
                    'IsITCApplicable' => $IsITCApplicable,
                    'CurrencyType' => $CurrencyType,
                    'TotalCost' => $subtotals,
                    'TotalMarkup' => 0,
                    'TotalDiscount' => $TotalDiscount,
                    'TotalTax' => (float) $totalCGST + (float) $totalSGST + (float) $totalIGST,
                    'NetAmount' => $totalpayable,
                    'Status' => 0,
                    'AgentSysId' => $AgentSysId,
                    'CreatedDate' => $CreateDate,
                    'ApprovedBy' => '',
                    'ApprovedDate' => $CreateDate,
                    'GstNumber' => ($IsITCApplicable == 1) ? $GstNumber : '',
                    'IsTDS' => $IsTDS,
                    'TDSAmount' => ($IsTDS == 1) ? $totalITDS : 0,
                    'PanNo' => ($IsTDS == 1) ? $PanCard : '',
                ];

                if (isset($billId) && !empty($billId)) {
                    $where = array('BillId =?' => $billId);
                    $this->db->update('TB_Supplier_Bill', $saveData, $where);
                    $walletRow = $SupplierMdl->getSupplierWalletDetails($SupplierSysId);
                    $currentData = date("Y-m-d H:i:s");
                    if (!$walletRow) {
                        $supplierDetails = $SupplierMdl->getSupplierDetails($SupplierSysId);
                        $CurrencyType = $supplierDetails['CurrencyType'];
                        $supplierWalletData = [
                            "SupplierSysId" => $SupplierSysId,
                            "BalanceAmount" => 0,
                            "CurrencyType" => $CurrencyType,
                            "UpdateDate" => $currentData,
                            "IsMarkForDel" => 0,
                            "IsActive" => 1
                        ];
                        $WalletId = $modelTBOMdl->insertData('TB_Supplier_Wallet', $supplierWalletData);
                    } else {
                        $WalletId = $walletRow['WalletId'];
                    }

                    $newTotalPayableAmount = $totalpayable;
                    $saveData = [
                        'BalanceAmount' => new Zend_Db_Expr("BalanceAmount - $newTotalPayableAmount"),
                        'UpdateDate' => date('Y-m-d H:i:s'),
                        'IsMarkForDel' => 0,
                        'IsActive' => 1,
                    ];
                    $whereQuery1 = array('WalletId = ? ' => $WalletId, 'SupplierSysId = ? ' => $SupplierSysId);
                    $modelTBOMdl->updateData('TB_Supplier_Wallet', $saveData, $whereQuery1);
                    $BalanceAmountSP = $agencyMdl->getCreditBalanceSupplier($WalletId, $SupplierSysId);
                    $dt = DateTime::createFromFormat('U.u', microtime(true));
                    $formatted = $dt->format("Y-m-d H:i:s") . '.' . substr($dt->format("u"), 0, 3);
                    $walletHistory = [
                        "WalletId" => $WalletId,
                        "SupplierId" => $SupplierSysId,
                        "TPSysId" => 0,
                        "TransactionType" => 0, // Credit  // 0 Debit
                        "InvoiceNo" => $InvoiceNo,
                        "ReferenceType" => 'Bill Received - ' . $InvoiceNo,
                        "CurrencyType" => $CurrencyType,
                        "TotalAmount" => $newTotalPayableAmount,
                        "PaidAmount" => $newTotalPayableAmount,
                        "BankCharges" => 0,
                        "OtherCharges" => 0,
                        "CGST" => $totalCGST,
                        "SGST" => $totalSGST,
                        "IGST" => $totalIGST,
                        "PaymentMode" => 0,
                        "Balance" => $BalanceAmountSP,
                        "TransactionDate" => $currentData,
                        "Remarks" => $Remarks,
                        "AgentSysId" => $AgentSysId,
                        "IsApproved" => 1,
                        "OTPCode" => 0,
                        "CodeValidFrom" => $currentData,
                        "CodeValidTo" => $currentData,
                        "CreateDate" => $currentData,
                        "UpdateDate" => $formatted,
                        "IsActive" => 1,
                        "IsMarkForDel" => 0
                    ];
                    $modelTBOMdl->insertData('TB_Supplier_Wallet_History', $walletHistory);
                    $this->db->delete('TB_Supplier_Bill_Items', $where);
                    foreach ($post['totalamount'] as $key => $item) {
                        $proposalId = isset($post['proposalId'][$key]) ? $post['proposalId'][$key] : '';
                        $checkIfExit = $SupplierMdl->checkProposalIdExists($proposalId);
                        if (empty($checkIfExit)) {
                            $message = 'Please check the ProposalId';
                            $response = ['status' => 'false', 'message' => 'Please check the ProposalId', 'BillId' => ''];
                            $flashMessenger = $this->_helper->getHelper('FlashMessenger');
                            $flashMessenger->setNamespace('sucess')->addMessage($message);
                        }
                        $additeam = [
                            'BillId' => $billId,
                            'Title' => isset($post['misxItems_name'][$key]) ? $post['misxItems_name'][$key] : '',
                            'Description' => isset($post['description'][$key]) ? $post['description'][$key] : '',
                            'SACCode' => isset($post['Items_SAC_Code'][$key]) ? $post['Items_SAC_Code'][$key] : '',
                            'Quantity' => isset($post['qty'][$key]) ? $post['qty'][$key] : 1,
                            'Rate' => isset($post['rates'][$key]) ? $post['rates'][$key] : 0,
                            'Markup' => 0,
                            'Discount' => 0,
                            'SGST' => ($IsITCApplicable == 1) ? $post['sgst'][$key] : 0,
                            'CGST' => ($IsITCApplicable == 1) ? $post['cgst'][$key] : 0,
                            'IGST' => ($IsITCApplicable == 1) ? $post['igst'][$key] : 0,
                            'TDS' => $post['tds'][$key],
                            'TotalAmount' => $item,
                            'ProposalId' => $proposalId,
                        ];
                        $result = $this->db->insert('TB_Supplier_Bill_Items', $additeam);
                    }
                    $response = array('status' => 'success', 'message' => 'Bill Updated successfully', 'BillId' => $billId);
                    echo json_encode($response);
                } else {

                    $billId = $objPackage->insertData('TB_Supplier_Bill', $saveData);
                    $walletRow = $SupplierMdl->getSupplierWalletDetails($SupplierSysId);
                    $currentData = date("Y-m-d H:i:s");
                    if (!$walletRow) {
                        $supplierDetails = $SupplierMdl->getSupplierDetails($SupplierSysId);
                        $CurrencyType = $supplierDetails['CurrencyType'];
                        $supplierWalletData = [
                            "SupplierSysId" => $SupplierSysId,
                            "BalanceAmount" => 0,
                            "CurrencyType" => $CurrencyType,
                            "UpdateDate" => $currentData,
                            "IsMarkForDel" => 0,
                            "IsActive" => 1
                        ];
                        $WalletId = $modelTBOMdl->insertData('TB_Supplier_Wallet', $supplierWalletData);
                    } else {
                        $WalletId = $walletRow['WalletId'];
                    }


                    $newTotalPayableAmount = $totalpayable;
                    $saveData = [
                        'BalanceAmount' => new Zend_Db_Expr("BalanceAmount - $newTotalPayableAmount"),
                        'UpdateDate' => date('Y-m-d H:i:s'),
                        'IsMarkForDel' => 0,
                        'IsActive' => 1,
                    ];
                    $whereQuery1 = array('WalletId = ? ' => $WalletId, 'SupplierSysId = ? ' => $SupplierSysId);
                    $modelTBOMdl->updateData('TB_Supplier_Wallet', $saveData, $whereQuery1);
                    $BalanceAmountSP = $agencyMdl->getCreditBalanceSupplier($WalletId, $SupplierSysId);
                    $dt = DateTime::createFromFormat('U.u', microtime(true));
                    $dt->setTimezone(new DateTimeZone('Asia/Kolkata'));
                    $formatted = $dt->format("Y-m-d H:i:s") . '.' . substr($dt->format("u"), 0, 3);
                    $walletHistory = [
                        "WalletId" => $WalletId,
                        "SupplierId" => $SupplierSysId,
                        "TPSysId" => 0,
                        "TransactionType" => 0, // Credit  // 0 Debit
                        "InvoiceNo" => $InvoiceNo,
                        "ReferenceType" => 'Bill Received - ' . $InvoiceNo,
                        "CurrencyType" => $CurrencyType,
                        "TotalAmount" => $newTotalPayableAmount,
                        "PaidAmount" => $newTotalPayableAmount,
                        "BankCharges" => 0,
                        "OtherCharges" => 0,
                        "CGST" => $totalCGST,
                        "SGST" => $totalSGST,
                        "IGST" => $totalIGST,
                        "PaymentMode" => 0,
                        "Balance" => $BalanceAmountSP,
                        "TransactionDate" => $currentData,
                        "Remarks" => $Remarks,
                        "AgentSysId" => $AgentSysId,
                        "IsApproved" => 1,
                        "OTPCode" => 0,
                        "CodeValidFrom" => $currentData,
                        "CodeValidTo" => $currentData,
                        "CreateDate" => $currentData,
                        "UpdateDate" => $formatted,
                        "IsActive" => 1,
                        "IsMarkForDel" => 0
                    ];
                    $modelTBOMdl->insertData('TB_Supplier_Wallet_History', $walletHistory);

                    foreach ($post['totalamount'] as $key => $item) {
                        $proposalId = isset($post['proposalId'][$key]) ? $post['proposalId'][$key] : '';
                        $checkIfExit = $SupplierMdl->checkProposalIdExists($proposalId);
                        if (empty($checkIfExit)) {
                            $message = 'Please check the ProposalId';
                            $response = ['status' => 'false', 'message' => 'Please check the ProposalId', 'BillId' => ''];
                            $flashMessenger = $this->_helper->getHelper('FlashMessenger');
                            $flashMessenger->setNamespace('sucess')->addMessage($message);
                        }
                        $additeam = [
                            'BillId' => $billId,
                            'Title' => isset($post['misxItems_name'][$key]) ? $post['misxItems_name'][$key] : '',
                            'Description' => isset($post['description'][$key]) ? $post['description'][$key] : '',
                            'SACCode' => isset($post['Items_SAC_Code'][$key]) ? $post['Items_SAC_Code'][$key] : '',
                            'Quantity' => isset($post['qty'][$key]) ? $post['qty'][$key] : 1,
                            'Rate' => isset($post['rates'][$key]) ? $post['rates'][$key] : 0,
                            'Markup' => 0,
                            'Discount' => 0,
                            'SGST' => ($IsITCApplicable == 1) ? $post['sgst'][$key] : 0,
                            'CGST' => ($IsITCApplicable == 1) ? $post['cgst'][$key] : 0,
                            'IGST' => ($IsITCApplicable == 1) ? $post['igst'][$key] : 0,
                            'TDS' => $post['tds'][$key],
                            'TotalAmount' => $item,
                            'ProposalId' => $proposalId,
                        ];
                        $objPackage->insertData('TB_Supplier_Bill_Items', $additeam);
                    }

                    $response = array('status' => 'success', 'message' => 'Bill created successfully', 'BillId' => $billId);
                    echo json_encode($response);
                }

                $flashMessenger = $this->_helper->getHelper('FlashMessenger');
                $flashMessenger->setNamespace('sucess')->addMessage($message);
                $this->_helper->redirector('manage-bill', 'supplier', 'finance');
            } catch (Exception $e) {
                http_response_code(500);
                echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
            }
        }
        if (isset($billId) && !empty($billId)) {
            $secureCode = Catabatic_ValidateCustomer::secureCode(trim(base64_encode($billId)), 1);
            if ($secureCode != $code) {
                echo "Please check your request parameters";
                exit;
            }
            $obj = new Travel_Model_TblSupplier();
            $post = $obj->SupplierBillRow($billId, $ICSourceSysId);
            $postD = $obj->SupplierBillItemDetailList($billId, $ICSourceSysId);
            $objCurrency = new Travel_Model_TblCurrency();
            $this->view->arrCurrencyTypes = $objCurrency->getCurrencyTypes();
            $this->view->post = $post;
            $this->view->postD = $postD;
            $this->view->BillId = $billId;
        }
        $ARR_SALUTION = unserialize(ARR_SALUTION);
        $ARR_CUSTOMER_RELATION = unserialize(ARR_CUSTOMER_RELATION);
        $this->view->ARR_CUSTOMER_RELATION = $ARR_CUSTOMER_RELATION;
        $this->view->ARR_SALUTION = $ARR_SALUTION;
    }

    public function previewInvoiceAction() {
//        error_reporting(E_ALL);
        $AgencySysId = $this->intLoggedinUserAgencySysId;
        $this->_helper->layout->disableLayout();
        $request = Zend_Controller_Front::getInstance()->getRequest();
        if ($request->isPost()) {
            $post = $request->getPost();
//            echo '<pre>';print_r($post);echo '</pre>';die;
            $objAgency = new Travel_Model_TblAgency();
            $objState = new Travel_Model_TblState();
            $AgencyData = $objAgency->getUserDataByAgency($AgencySysId);
            $AddressAgency = $objAgency->getAddressByAgency($AgencySysId);
            $BankDetailsAgency = $objAgency->getBankDetailsByAgency($AgencySysId);
            $this->view->getStates = $objState->getStates();

            $this->view->post = $post;
            $this->view->AgencyData = $AgencyData;
            $this->view->AddressAgency = $AddressAgency;
            $this->view->BankDetailsAgency = $BankDetailsAgency;
        }
    }

    public function updateBillAction() {
//        error_reporting(E_ALL);
        $objCountry = new Travel_Model_TblCountry();
        $objVisa = new Travel_Model_TblVisa();
        $obj = new Travel_Model_TblSupplier();
        $objState = new Travel_Model_TblState();
        $objAgency = new Travel_Model_TblAgency();
        $BillId = base64_decode($this->getRequest()->getParam("id"));
        $this->view->BillId = $BillId;
        $this->view->MarketPlace = $objVisa->MarketPlace();
        $this->view->intLoggedinUserAgencySysId = $ICSourceSysId = $this->intLoggedinUserAgencySysId;
        $AgentSysId = $this->intLoggedinUserId;
        $this->view->ICSourceSysId = $ICSourceSysId;
        $this->view->arrCountryList = $objCountry->getCountryList();
        $this->view->MarketPlace = $objVisa->MarketPlace();
        $this->view->getStates = $objState->getStates();
        $AddressAgency = $objAgency->getAddressByAgency($ICSourceSysId);
        $this->view->AddressAgency = $AddressAgency;
        $this->view->getAgencyData = $getAgencyData = $objAgency->getAgencyData($ICSourceSysId);
        $_crmcustomerObj = new Travel_Model_CRM_Customer();
        $this->view->agencyUser = $_crmcustomerObj->getAllAgencyUserList('', $this->intLoggedinUserAgencySysId);
        $params = Zend_Controller_Front::getInstance()->getRequest()->getParams();
        if ($this->getRequest()->isPost()) {
            $request = Zend_Controller_Front::getInstance()->getRequest();
            $post = $request->getPost();
            //echo "<pre>";print_r($post);exit;
            $CreateDate = date('Y-m-d H:i:s');

            $SupplierSysId = isset($post['hidden_selected_supplier_sys_id']) ? $post['hidden_selected_supplier_sys_id'] : 0;
            $BillNumber = isset($post['bill_no']) ? $post['bill_no'] : 0;
            $BillDate = isset($post['dateofissue']) ? $post['dateofissue'] : $CreateDate;
            $BillDueDate = isset($post['duedates']) ? $post['duedates'] : '';
            $BillDate = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($BillDate, 'd/m/y');
            $BillDueDate = Zend_Controller_Action_HelperBroker::getStaticHelper('DateFormat')->cal2Db($BillDueDate, 'd/m/y');
            $IsITCApplicable = isset($post['client_gst']) ? $post['client_gst'] : 0;
            $CurrencyType = isset($post['Currency']) ? $post['Currency'] : null;
            $totalpayable = isset($post['totalpayable']) ? $post['totalpayable'] : 0;
            $TotalMarkup = isset($post['TotalMarkup']) ? $post['TotalMarkup'] : 0;
            $TotalDiscount = isset($post['Sumdiscount']) ? $post['Sumdiscount'] : 0;
            $TotalTax = isset($post['TotalTax']) ? $post['TotalTax'] : 0;
            $NetAmount = isset($post['subtotals']) ? $post['subtotals'] : 0;
            $GstNumber = isset($post['client_gst_no']) ? $post['client_gst_no'] : '';
            $this->view->intLoggedinUserAgencySysId = $AgencySysId = $this->intLoggedinUserAgencySysId;
            $AgentSysId = $this->intLoggedinUserId;

            $saveData = [
                'SupplierSysId' => $SupplierSysId,
                'AgencySysId' => $AgencySysId,
                'BillNumber' => $BillNumber,
                'BillDate' => $BillDate,
                'BillDueDate' => $BillDueDate,
                'IsITCApplicable' => $IsITCApplicable,
                'CurrencyType' => $CurrencyType,
                'TotalCost' => $totalpayable,
                'TotalMarkup' => 0,
                'TotalDiscount' => $TotalDiscount,
                'TotalTax' => $TotalTax,
                'NetAmount' => $NetAmount,
                'Status' => 0,
                'AgentSysId' => $AgentSysId,
                'ApprovedBy' => '',
                'ApprovedDate' => $CreateDate,
                'GstNumber' => ($IsITCApplicable == 1) ? $GstNumber : '',
            ];

            try {
                $where = array('BillId =?' => $BillId);
                $this->db->update('TB_Supplier_Bill', $saveData, $where);
                //$this->db->insert('TB_Agency_Miscellaneous', $insert);
                //$lastInsertId = $this->db->lastInsertId('TB_Agency_Miscellaneous');
                $insertDelete = array(
                    'IsActive' => '0',
                    'IsMarkForDel' => '1'
                );
                $this->db->delete('TB_Supplier_Bill_Items', $where);
                if ($BillId) {
                    foreach ($post['totalamount'] as $key => $item) {
                        $additeam = [
                            'BillId' => $BillId,
                            'Title' => isset($post['misxItems_name'][$key]) ? $post['misxItems_name'][$key] : '',
                            'Description' => isset($post['description'][$key]) ? $post['description'][$key] : '',
                            'SACCode' => isset($post['Items_SAC_Code'][$key]) ? $post['Items_SAC_Code'][$key] : '',
                            'Quantity' => isset($post['qty'][$key]) ? $post['qty'][$key] : 1,
                            'Rate' => isset($post['rates'][$key]) ? $post['rates'][$key] : 0,
                            'Markup' => 0,
                            'Discount' => 0,
                            'SGST' => $post['sgst'][$key],
                            'CGST' => $post['cgst'][$key],
                            'IGST' => $post['igst'][$key],
                            'TDS' => $post['tds'][$key],
                            'TotalAmount' => $item,
                        ];
                        $result = $this->db->insert('TB_Supplier_Bill_Items', $additeam);
                    }
                }
            } catch (Exception $ex) {
                die('There has been an error. ' . $ex->getMessage());
            }
            //print_r($result);
            //die('d');

            if (!empty($result) && $result > 0) {
                $NetAmount = isset($post['InvoiceValue']) && !empty($post['InvoiceValue']) ? $post['InvoiceValue'] : '0';
                $Tax = 0;
                $Currency = isset($post['Currency']) ? $post['Currency'] : '0';
                $BilledTo = isset($post['']) ? $post['customerId'] : '0';
                $strInvoiceNumber = isset($post['bill_no']) ? $post['bill_no'] : '0';
                $flashMessenger = $this->_helper->getHelper('FlashMessenger');
                $flashMessenger->setNamespace('success')->addMessage('Update successfully');
                $this->_helper->redirector('manage-bill', 'supplier', 'finance');
            } else {
                $flashMessenger = $this->_helper->getHelper('FlashMessenger');
                $flashMessenger->setNamespace('error')->addMessage('Oops! unable update! please try again.');
                $this->_helper->redirector('manage-bill', 'supplier', 'finance');
            }
        }

        if (isset($BillId) && !empty($BillId)) {
            $post = $obj->SupplierBillRow($BillId, $ICSourceSysId);
            $postD = $obj->SupplierBillItemDetailList($BillId, $ICSourceSysId);
            $objCurrency = new Travel_Model_TblCurrency();
            $this->view->arrCurrencyTypes = $objCurrency->getCurrencyTypes();
            $this->view->post = $post;
            $this->view->postD = $postD;
            $this->view->BillId = $BillId;
        }
    }

    public function printbillAction() {
//        error_reporting(E_ALL);
        $code = $this->getRequest()->getParam('code');
        $secureCode = Catabatic_ValidateCustomer::secureCode(trim($this->getRequest()->getParam('id')), 1);
        if ($secureCode != $code) {
            echo "Please check your request parameters";
            exit;
        }
        $this->_helper->layout->disableLayout();
        $AgencySysId = $this->intLoggedinUserAgencySysId;
        $AgentSysId = $this->intLoggedinUserId;
        $AgentName = $this->intLoggedinUserFirstName;
        $BillId = base64_decode($this->getRequest()->getParam("id"));
        $Resend = $this->getRequest()->getParam("Resend");
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $obj = new Travel_Model_TblSupplier();
        $objAgency = new Travel_Model_TblAgency();
        $post = $obj->SupplierBillRow($BillId, $AgencySysId);
        $postD = $obj->SupplierBillItemDetailList($BillId, $AgencySysId);
        $AgencyData = $objAgency->getUserDataByAgency($AgencySysId);
        $AddressAgency = $objAgency->getAddressByAgency($AgencySysId);
        $BankDetailsAgency = $objAgency->getBankDetailsByAgency($AgencySysId);
        $fullBaseUrl = $this->view->baseUrl();
        $InvoiceAgentSysId = $post['AgentSysId'];
        $PrintPaymentUrl = $fullBaseUrl . '/publicmiscellaneous/printinvoice/id/' . base64_encode($post['BillId']) . '/ag/' . base64_encode($post['AgencySysId']);
        // $agentDetailsInvoice = $this->_crmcusttravelplan->getAgentDetails($InvoiceAgentSysId);
        $agentDetails = $this->_crmcusttravelplan->getAgentDetails($AgentSysId);
        if ($agentDetails['IsB2CSite'] == 1) {
            $PrintPaymentUrl = $agentDetails['Url'] . "detail/index/view/id/" . base64_encode($PrintPaymentUrl);
        } else if (($agentDetails['IsB2CSite'] == 2) && ($agentDetails['IsSiteType'] == 1)) {
            $PrintPaymentUrl = $agentDetails['Url'] . "hellogtx/index.html?id=" . base64_encode($PrintPaymentUrl);
        } else if (($agentDetails['IsB2CSite'] == 2) && ($agentDetails['IsSiteType'] == 0)) {
            $PrintPaymentUrl = $agentDetails['Url'] . "hellogtx/gtx.php?id=" . base64_encode($PrintPaymentUrl);
        }
        //        echo '<pre>';print_r($PrintPaymentUrl);echo '</pre>';
        // echo '<pre>';
        // print_r($post);
        // echo '</pre>';
        // die;
        //echo $Resend;die;
        if ($Resend == '1') {
            $arrpost = array(
                'post' => $post,
                'postD' => $postD,
                'AgencyData' => $AgencyData,
                'AddressAgency' => $AddressAgency,
                'BankDetailsAgency' => $BankDetailsAgency,
                'intLoggedinUserAgencySysId' => $AgencySysId,
                'intLoggedinUserId' => $AgentSysId,
                'AgentName' => $AgentName,
                'PrintPaymentUrl' => $PrintPaymentUrl,
            );
            //            echo '<pre>';print_r($arrpost);die;
            $emailStatus = Zend_Controller_Action_HelperBroker::getStaticHelper('EmailTemplate')->SendmiscellaneousInvoice($arrpost);

            if ($emailStatus == '1') {
                $flashMessenger = $this->_helper->getHelper('FlashMessenger');
                $flashMessenger->setNamespace('success')->addMessage('Invoice sent succesfully');
                //                $this->_helper->FlashMessenger()->setNamespace('success')->addMessage('Invoice sent succesfully');
                $this->_helper->redirector('manage-bill', 'supplier', 'finance');
            } else {
                $flashMessenger = $this->_helper->getHelper('FlashMessenger');
                $flashMessenger->setNamespace('error')->addMessage('Oops! unable to send mail! please try again.');
                //                $this->_helper->FlashMessenger()->setNamespace('error')->addMessage('Oops! unable to send mail! please try again.');
                $this->_helper->redirector('manage-bill', 'supplier', 'finance');
            }
            //echo '<pre>';print_r($emailStatus);echo '</pre>';die;
        }

        $this->view->post = $post;
        $this->view->postD = $postD;
        $this->view->AgencyData = $AgencyData;
        $this->view->AddressAgency = $AddressAgency;
        $this->view->BankDetailsAgency = $BankDetailsAgency;
    }

    public function changeSupplierAction() {
        $this->view->layout()->disableLayout();
        $objAgency = new Travel_Model_TblAgency();
        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        $ServiceTaxNo = isset($sessionLogin_user->agencyDetails['ServiceTaxNo']) ? $sessionLogin_user->agencyDetails['ServiceTaxNo'] : '';
        $this->view->intLoggedinUserAgencySysId = $ICSourceSysId = $this->intLoggedinUserAgencySysId;
        if ($this->getRequest()->isPost()) {
            $request = Zend_Controller_Front::getInstance()->getRequest();
            $post = $request->getPost();
            $SupplierSysId = $post['SupplierSysId'] ? $post['SupplierSysId'] : 0;
            $type = $post['type'] ? $post['type'] : 1;
            if ($SupplierSysId > 0) {
                $supplierData = $objAgency->getSupplierDetails($ICSourceSysId, $SupplierSysId);
                $SupplierCurrencyType = $supplierData['CurrencyType'];
                $GstApplicable = ($supplierData['GstApplicable'] == 1) ? $supplierData['GstApplicable'] : 0;
                $GSTNo = $supplierData['GSTNo'];
                $Symbol = $supplierData['Symbol'];
//                echo"<pre>";print_r($supplierData);die('dd');
                $gstvalidate = [];
                if ($GstApplicable == 1) {
                    $gstvalidate = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->gstvalidate($GSTNo, $ServiceTaxNo);
                }
                $data = [
                    'Symbol' => $Symbol,
                    'SupplierCurrencyType' => $SupplierCurrencyType,
                    'gstvalidate' => $gstvalidate,
                    'GstApplicable' => $GstApplicable,
                    'GSTNo' => $GSTNo,
                    'Type' => 1
                ];
                $response = array('success' => true, 'data' => $data, 'message' => 'Changed successfully');
                echo json_encode($response);
                exit;
            } else
            if ($type == 2) {
                $GstApplicable = $post['IsApplicable'] ? $post['IsApplicable'] : 0;
                $GSTNo = $post['GSTNumber'] ? $post['GSTNumber'] : '';
                $gstvalidate = [];
                if ($GstApplicable == 1) {
                    $gstvalidate = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->gstvalidate($GSTNo, $ServiceTaxNo);
                }
                $data = [
                    'gstvalidate' => $gstvalidate,
                    'GstApplicable' => $GstApplicable,
                    'GSTNo' => $GSTNo,
                    'Type' => 2
                ];
                $response = array('success' => true, 'data' => $data, 'message' => 'Changed successfully');
                echo json_encode($response);
                exit;
            } else {
                $response = array('success' => false, 'message' => 'Unable to  send. try again');
                echo json_encode($response);
                exit;
            }
        } else {
            $response = array('success' => false, 'message' => 'Unable to  send. try again');
            echo json_encode($response);
            exit;
        }
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit