| 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/models/ |
Upload File : |
<?php
//Prashant
require_once('BaseModel.php');
class Travel_Model_TblCreditNote extends BaseModel
{
protected $db = NULL;
public $intId = NULL;
public $strCondition = NULL;
public $searchArr = NULL;
public $searchActivitiesArr = NULL;
public $baseUrl;
/***************************************/
public function __construct()
{
$request = Zend_Controller_Front::getInstance()->getRequest();
$this->baseUrl = $request->getScheme() . '://' . $request->getHttpHost();
$this->db = Zend_Db_Table::getDefaultAdapter();
}
public function __destruct()
{
$this->db->closeConnection();
}
public function addItems($ICSourceSysId)
{
$request = Zend_Controller_Front::getInstance()->getRequest();
if ($request->isPost()) {
$post = $request->getPost();
$CreateDate = date('Y-m-d H:i:s');
$mis_id = isset($post['mis_id']) && !empty($post['mis_id']) ? $post['mis_id'] : '';
//echo '<pre>';print_r($post);die;
try {
$insert = array(
'ICSourceSysId' => $ICSourceSysId,
'IsAgentSpec' => !empty($ICSourceSysId && $ICSourceSysId > 0) ? $ICSourceSysId : '0',
'MiscItemName' => isset($post['itemname']) && !empty($post['itemname']) ? $post['itemname'] : 'NA',
'MiscCategory' => isset($post['category']) && !empty($post['category']) ? $post['category'] : '0',
'MiscReverceCharge' => isset($post['reverce_charge']) && !empty($post['reverce_charge']) ? $post['reverce_charge'] : '0',
'MiscSupplier' => isset($post['hidden_selected_supplier_sys_id']) && !empty($post['hidden_selected_supplier_sys_id']) ? $post['hidden_selected_supplier_sys_id'] : '0',
'MiscSupplierName' => isset($post['supplier_name']) && !empty($post['supplier_name']) ? $post['supplier_name'] : '0',
'MiscSacHacCode' => isset($post['sac_hac_code']) && !empty($post['sac_hac_code']) ? $post['sac_hac_code'] : 'NA',
'MiscCost' => isset($post['cost']) && !empty($post['cost']) ? $post['cost'] : '0',
'GSTPercentage' => isset($post['GSTPercentage']) && !empty($post['GSTPercentage']) ? $post['GSTPercentage'] : '0',
'MiscGST' => isset($post['gst']) && !empty($post['gst']) ? $post['gst'] : '0',
'MiscTotalCostGst' => isset($post['total_costgst']) && !empty($post['total_costgst']) ? $post['total_costgst'] : '0',
'MiscReverceGst' => isset($post['reverse_gst']) && !empty($post['reverse_gst']) ? $post['reverse_gst'] : '0',
'MiscTotalCost' => isset($post['total_cost']) && !empty($post['total_cost']) ? $post['total_cost'] : '0',
'CreateDate' => $CreateDate,
'UpdateDate' => $CreateDate,
'ApproveDate' => $CreateDate,
'IsActive' => 1,
'IsApproved' => !empty($ICSourceSysId && $ICSourceSysId > 0) ? 0 : 1,
'IsMarkForDel' => 0
);
if (!empty($mis_id) && $mis_id > 0) {
$where = array('InvnMiscSysId = ? ' => $mis_id);
$this->db->update('TB_MP_Inventory_Miscellaneous', $insert, $where);
$lastInsertId = $mis_id;
} else {
$this->db->insert('TB_MP_Inventory_Miscellaneous', $insert);
$lastInsertId = $this->db->lastInsertId('TB_MP_Inventory_Miscellaneous');
}
$markup_id = isset($post['markup_id']) && !empty($post['markup_id']) ? $post['markup_id'] : '';
$MarkUpType = isset($post['markup_type']) && !empty($post['markup_type']) ? $post['markup_type'] : '';
$markup_value = isset($post['markup_value']) && !empty($post['markup_value']) ? $post['markup_value'] : '';
$MrkSysId = isset($post['MrkSysId']) && !empty($post['MrkSysId']) ? $post['MrkSysId'] : '';
if ($markup_id) {
foreach ($markup_id as $k => $val) {
$insert_M = array(
'ICSourceSysId' => $ICSourceSysId,
'IsAgentSpec' => !empty($ICSourceSysId && $ICSourceSysId > 0) ? $ICSourceSysId : '0',
'InvnMiscSysId' => $lastInsertId,
'MPType' => $markup_id[$k],
'MarkUpType' => $MarkUpType[$k],
'MarkUp' => $markup_value[$k],
'CreateDate' => $CreateDate,
'UpdateDate' => $CreateDate,
'ApproveDate' => $CreateDate,
'IsActive' => 1,
'IsApproved' => !empty($ICSourceSysId && $ICSourceSysId > 0) ? 0 : 1,
'IsMarkForDel' => 0
);
if (!empty($MrkSysId) && array_key_exists($k, $MrkSysId)) {
$where = array('MrkSysId = ? ' => $MrkSysId[$k]);
$this->db->update('TB_MP_StdMarkup_Miscellaneous', $insert_M, $where);
} else {
$this->db->insert('TB_MP_StdMarkup_Miscellaneous', $insert_M);
}
//echo '<pre>';
//print_r($insert_M);
}
}
return true;
} catch (Exception $e) {
die('There has been an error. ' . $e->getMessage());
}
return 0;
//echo '<pre>';print_r($post);
}
}
public function InvMiscellaneousDetails($InvnVisaAllSysId, $ICSourceSysId)
{
$select = $this->db->select();
$selectarray = array('InvnMiscSysId', 'ICSourceSysId', 'MiscItemName', 'MiscCategory', 'MiscReverceCharge', 'GSTPercentage', 'MiscSupplier', 'MiscSacHacCode', 'MiscCost', 'MiscGST', 'MiscTotalCostGst', 'MiscReverceGst', 'MiscTotalCost', 'IsActive', 'IsApproved');
$supplierarray = array('SupplierName');
$select->from(array('tb1' => "TB_MP_Inventory_Miscellaneous"), $selectarray);
$select->joinLeft(array('tb3' => "TB_IC_Supplier"), "tb1.MiscSupplier = tb3.SupplierSysId", $supplierarray);
$select->where("tb1.InvnMiscSysId =?", $InvnVisaAllSysId);
$select->where("tb1.ICSourceSysId =?", $ICSourceSysId);
$select->where("tb1.IsMarkForDel =?", 0);
$result = $this->db->fetchRow($select);
return $result;
}
public function InvMiscellaneousList($ICSourceSysId)
{
$select = $this->db->select();
$selectarray = array('InvnMiscSysId', 'ICSourceSysId', 'MiscItemName', 'MiscCategory', 'MiscReverceCharge', 'GSTPercentage', 'MiscSupplier', 'MiscSacHacCode', 'MiscCost', 'MiscGST', 'MiscTotalCostGst', 'MiscReverceGst', 'MiscTotalCost', 'IsActive', 'IsApproved');
$supplierarray = array('SupplierName');
$select->from(array('tb1' => "TB_MP_Inventory_Miscellaneous"), $selectarray);
$select->joinLeft(array('tb3' => "TB_IC_Supplier"), "tb1.MiscSupplier = tb3.SupplierSysId", $supplierarray);
if (!empty($ICSourceSysId) && $ICSourceSysId > 0) {
$select->where("tb1.ICSourceSysId =?", $ICSourceSysId);
}
$select->where("tb1.IsMarkForDel =?", 0);
$select->order(array('InvnMiscSysId DESC'));
$result = $this->db->fetchAll($select);
return $result;
}
public function AgencyMiscellaneousList($ICSourceSysId,$fromDate=null, $currentDate=null)
{
$select = $this->db->select();
$selectarray = array('MasterMiscSysId', 'ICSourceSysId', 'CONVERT(VARCHAR(24),InvoiceDate,103) as InvoiceDate', 'CONVERT(VARCHAR(24),PaymentDueDate,103) as PaymentDueDate', 'InvoiceNumber', 'ClientGST', 'ClientGSTNumber', 'Currency', 'TotalInvoiceValue', 'TotalCGST', 'TotalSGST', 'TotalIGST', 'OtherDiscount', 'TotalAdvance', 'TotalDueAmount', 'InvoiceValue', 'otherDiscountVal', 'CreateDate', 'InvoiceStatus','client_state');
$customerarray = array('CustomerSysId', 'Contacts', 'CitySysId', 'EmailId', 'Address', 'FirstName', "(RTRIM(LTRIM(tb2.FirstName)) + ' ' + RTRIM(LTRIM(tb2.LastName))) as FullName");
$Currencyarray = array('Symbol', 'Title', 'Icon');
$b2bagencyColumn = array('AgencyName as CompanyName', 'UserSysId', 'IsB2BAgent', 'GSTIN', 'Address as AgAddress', 'PinCode as AgPinCode', 'StateOrZoneSysId as AgStateOrZoneSysId', 'ContactNo1 as AgContact', 'EmailId as AgEmailId', 'CitySysId as AgCitySysId', 'FirstName as AgFirstName','LastName as AgLastName');
$select->from(array('tb1' => "TB_Agency_Credit_Note"), $selectarray);
$select->joinLeft(array('tb2' => "TB_Agency_Customer"), "tb1.BilledTo = tb2.CustomerSysId", $customerarray);
$select->joinLeft(array('tb3' => "TB_Master_Currency"), "tb1.Currency = tb3.CurrencyType", $Currencyarray);
$select->joinLeft(array('tb6' => "TB_Agency_User"), "tb6.UserSysId = tb1.AgentSysId", $b2bagencyColumn);
$select->joinLeft(array('tb7' => "TB_Master_Geo_City"), "tb7.CityId = tb6.CitySysId", array('Title as AgCityName'));
$select->joinLeft(array('tb8' => "TB_Master_Geo_City"), "tb8.CityId = tb2.CitySysId", array('Title as CityName'));
if (!empty($ICSourceSysId) && $ICSourceSysId > 0) {
$select->where("tb1.ICSourceSysId =?", $ICSourceSysId);
}
if (!empty($fromDate) && !empty($currentDate)) {
$start_date_formatted = date('Y-m-d', strtotime($fromDate)).' 00:00:00';
$end_date_formatted = date('Y-m-d', strtotime($currentDate)).' 00:00:00';
$select->where("InvoiceDate >= ?", $start_date_formatted);
$select->where("InvoiceDate <= ?", $end_date_formatted);
}
$select->where("tb1.IsMarkForDel =?", 0);
$select->order(array('CreateDate DESC'));
$result = $this->db->fetchAll($select);
return $result;
}
public function AgencyMiscellaneousRow($MasterMiscSysId=null, $ICSourceSysId=null,$TPSysId=null,$MasterTPSysId=null)
{
$select = $this->db->select();
$selectarray = array('isDisplayMarkup', 'MasterMiscSysId', 'BilledTo', 'ICSourceSysId', 'AgentSysId', 'CONVERT(VARCHAR(24),InvoiceDate,103) as InvoiceDate', 'CONVERT(VARCHAR(24),PaymentDueDate,103) as PaymentDueDate','CONVERT(VARCHAR(20),PaymentDueDate,120) as PaymentDueDateDay', 'InvoiceNumber', 'ClientGST', 'ClientGSTNumber', 'Currency', 'TotalInvoiceValue', 'TotalCGST', 'TotalSGST', 'TotalIGST', 'OtherDiscount', 'TotalAdvance', 'TotalDueAmount', 'InvoiceValue', 'otherDiscountVal', 'CreateDate', 'notes', 'termsandcondition', 'SumdiscountItem', 'InvoiceStatus', 'client_state','ProposalID');
$customerarray = array('CustomerSysId', 'Contacts', 'EmailId', 'CitySysId', 'PinCode', 'Address', 'FirstName', "(RTRIM(LTRIM(tb2.FirstName)) + ' ' + RTRIM(LTRIM(tb2.LastName))) as FullName");
$Currencyarray = array('Symbol', 'Title', 'Icon');
$Statearray = array('Title as stateName');
$b2bagencyColumn = array('AgencyName as CompanyName', 'UserSysId', 'IsB2BAgent', 'GSTIN', 'Address as AgAddress', 'PinCode as AgPinCode', 'StateOrZoneSysId as AgStateOrZoneSysId', 'ContactNo1 as AgContact', 'EmailId as AgEmailId', 'CitySysId as AgCitySysId');
$select->from(array('tb1' => "TB_Agency_Credit_Note"), $selectarray);
$select->joinLeft(array('tb2' => "TB_Agency_Customer"), "tb1.BilledTo = tb2.CustomerSysId", $customerarray);
$select->joinLeft(array('tb3' => "TB_Master_Currency"), "tb1.Currency = tb3.CurrencyType", $Currencyarray);
$select->joinLeft(array('tb4' => "TB_Master_Geo_State"), "tb1.client_state = tb4.StateId", $Statearray);
$select->joinLeft(array('tb6' => "TB_Agency_User"), "tb6.UserSysId = tb2.CreatedByUserSysId", $b2bagencyColumn);
$select->joinLeft(array('tb7' => "TB_Master_Geo_City"), "tb7.CityId = tb6.CitySysId", array('Title as AgCityName'));
$select->joinLeft(array('tb8' => "TB_Master_Geo_City"), "tb8.CityId = tb2.CitySysId", array('Title as CityName'));
if (!empty($ICSourceSysId) && $ICSourceSysId > 0) {
$select->where("tb1.ICSourceSysId =?", $ICSourceSysId);
}
if (!empty($TPSysId) && $TPSysId > 0) {
$select->where("tb1.TPSysId =?", $TPSysId);
}
if (!empty($MasterTPSysId) && $MasterTPSysId > 0) {
$select->where("tb1.MasterTPSysId =?", $MasterTPSysId);
}
if (!empty($MasterMiscSysId) && $MasterMiscSysId > 0) {
$select->where("tb1.MasterMiscSysId =?", $MasterMiscSysId);
}
// $select->where("tb1.MasterMiscSysId =?", $MasterMiscSysId);
$select->where("tb1.IsMarkForDel =?", 0);
$select->order(array('CreateDate DESC'));
$result = $this->db->fetchRow($select);
return $result;
}
public function AgencyMiscellaneousPayentRow($MasterMiscPaySysId, $ICSourceSysId)
{
$select = $this->db->select();
$select->from(array('tb1' => "TB_Agency_Credit_Note_PaymentLog"));
$select->where("tb1.ICSourceSysId =?", $ICSourceSysId);
$select->where("tb1.MasterMiscPaySysId =?", $MasterMiscPaySysId);
$select->where("tb1.IsActive =?", 1);
$select->where("tb1.IsMarkForDel =?", 0);
$select->order(array('CreateDate DESC'));
$result = $this->db->fetchRow($select);
return $result;
}
public function AgencyMiscellaneousPayentRowPub($MasterMiscPaySysId)
{
$select = $this->db->select();
$select->from(array('tb1' => "TB_Agency_Credit_Note_PaymentLog"));
$select->where("tb1.MasterMiscPaySysId =?", $MasterMiscPaySysId);
$select->where("tb1.IsActive =?", 1);
$select->where("tb1.IsMarkForDel =?", 0);
$select->order(array('CreateDate DESC'));
$result = $this->db->fetchRow($select);
return $result;
}
public function AgencyMisDetailList($MasterMiscSysId, $ICSourceSysId)
{
$select = $this->db->select();
$selectarray = array('MasterMiscSysId', 'ICSourceSysId', 'MisxItems_name', 'Description', 'ItemQty', 'ItemRates', 'Total', 'DiscountType', 'Discount', 'TotalDiscount', 'TotalAmount', 'MarkupType', 'Markup', 'TotalMarkup', 'SubTotal', 'ServiceFeeTotal', 'GSTPercentage', 'TotalGST', 'SGST', 'CGST', 'IGST', 'ItemsSACCode');
$select->from(array('tb1' => "TB_Agency_Credit_Note_Details"), $selectarray);
if (!empty($ICSourceSysId) && $ICSourceSysId > 0) {
$select->where("tb1.ICSourceSysId =?", $ICSourceSysId);
}
$select->where("tb1.MasterMiscSysId =?", $MasterMiscSysId);
$select->where("tb1.IsMarkForDel =?", 0);
$select->order(array('CreateDate DESC'));
$result = $this->db->fetchAll($select);
return $result;
}
public function AgencyMisGetLastId($ICSourceSysId)
{
$select = $this->db->select();
$selectarray = array('InvoiceNumber');
if (!empty($ICSourceSysId) && $ICSourceSysId > 0) {
$select->where("tb1.ICSourceSysId =?", $ICSourceSysId);
}
$select->from(array('tb1' => "TB_Agency_Credit_Note"), $selectarray);
$select->order(array('MasterMiscSysId DESC'));
$result = $this->db->fetchRow($select);
return $result['InvoiceNumber'];
}
public function getItemsSearch($MiscItemName, $ICSourceSysId, $market_place)
{
$select = $this->db->select();
$selectarray = array('InvnMiscSysId', 'ICSourceSysId', 'MiscItemName', 'MiscCategory', 'MiscReverceCharge', 'GSTPercentage', 'MiscCost', 'MiscGST', 'MiscTotalCostGst', 'MiscReverceGst', 'MiscTotalCost', 'IsActive', 'IsApproved');
$select->from(array('tb1' => "TB_MP_Inventory_Miscellaneous"), $selectarray);
if (!empty($ICSourceSysId) && $ICSourceSysId > 0) {
$select->where("tb1.ICSourceSysId =?", $ICSourceSysId);
}
$select->where('MiscItemName LIKE ?', '%' . $MiscItemName . '%');
$select->where("tb1.IsMarkForDel =?", 0);
$select->order(array('MiscItemName ASC'));
$result = $this->db->fetchAll($select);
if (count($result) > 0) {
foreach ($result as $row) {
$dataName = $row['MiscItemName'];
$MarkupMiscList = $this->getItemMarkup($row['InvnMiscSysId'], $market_place, $ICSourceSysId);
$response[] = array('InvnMiscSysId' => $row['InvnMiscSysId'], 'MarkUpType' => $MarkupMiscList['MarkUpType'], 'MarkUp' => $MarkupMiscList['MarkUp'] + '0', 'MiscCost' => $row['MiscCost'], 'GSTPercentage' => $row['GSTPercentage'], 'value' => $dataName, 'label' => $dataName);
}
} else {
$response[] = array('InvnMiscSysId' => 0, 'MarkUpType' => 0, 'MarkUp' => 0, 'MiscCost' => 0, 'GSTPercentage' => 0, 'value' => 'Add New Item', 'label' => 'Add New Item');
}
return $response;
}
public function MarkupMiscList($InvnVisaSysId, $ICSourceSysId)
{
$select = $this->db->select();
$selectarray = array('MrkSysId', 'InvnMiscSysId', 'MPType', 'MarkUpType', 'MarkUp', 'ICSourceSysId');
$select->from(array('tb1' => "TB_MP_StdMarkup_Miscellaneous"), $selectarray);
$select->where("tb1.InvnMiscSysId =?", $InvnVisaSysId);
$select->where("tb1.ICSourceSysId =?", $ICSourceSysId);
$result = $this->db->fetchAll($select);
return $result;
}
public function getItemMarkup($item_id, $MPType, $ICSourceSysId)
{
$select = $this->db->select();
$selectarray = array('MrkSysId', 'InvnMiscSysId', 'MPType', 'MarkUpType', 'MarkUp', 'ICSourceSysId');
$select->from(array('tb1' => "TB_MP_StdMarkup_Miscellaneous"), $selectarray);
$select->where("tb1.InvnMiscSysId =?", $item_id);
$select->where("tb1.MPType =?", $MPType);
$select->where("tb1.ICSourceSysId =?", $ICSourceSysId);
$result = $this->db->fetchRow($select);
return $result;
}
public function CancelInvoice($DeleteId)
{
try {
$this->db->beginTransaction();
$insert = array(
'InvoiceStatus' => 3,
);
$where = array('MasterMiscSysId =?' => $DeleteId);
$this->db->update('TB_Agency_Credit_Note', $insert, $where);
$this->db->update('TB_Agency_Credit_Note_Details', $insert, $where);
$this->db->commit();
return true;
} catch (Exception $ex) {
die($ex->getMessage());
}
}
}