235 lines
10 KiB
PHP
235 lines
10 KiB
PHP
<?php
|
|
class Terms extends MY_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_inventory = $this->load->database("inventory", true);
|
|
$this->db_inventory_log = $this->load->database('inventory_log', true);
|
|
$this->db_onex = 'one_aditya';
|
|
}
|
|
|
|
function get_terms(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$id = 0;
|
|
if(isset($prm['id']) && intval($prm) > 0){
|
|
$id = $prm['id'];
|
|
$sql = "SELECT SupplierPaymentTermsID as id,
|
|
SupplierPaymentTermsCode as code,
|
|
SupplierPaymentTermsName as name,
|
|
SupplierPaymentTermsDescription as description,
|
|
DATE_FORMAT(SupplierPaymentTermsStartDate,'%d-%m-%Y') as start_date,
|
|
DATE_FORMAT(SupplierPaymentTermsEndDate,'%d-%m-%Y') as end_date
|
|
FROM supplierpaymentterms
|
|
WHERE
|
|
SupplierPaymentTermsSupplierID = ? AND SupplierPaymentTermsIsActive = 'Y' AND
|
|
( DATE(NOW()) BETWEEN DATE(SupplierPaymentTermsStartDate) AND DATE(SupplierPaymentTermsEndDate) )";
|
|
$query = $this->db_inventory->query($sql,$id);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("supplierpaymentterms rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
}
|
|
else{
|
|
$this->sys_error("Invalid Param ID");
|
|
exit;
|
|
}
|
|
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_term_detail(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$id = 0;
|
|
if(isset($prm['id']) && intval($prm) > 0){
|
|
$id = $prm['id'];
|
|
$sql = "SELECT SupplierPaymentTermsDetailID as id,
|
|
SupplierPaymentTermsDetailItemID as item_id,
|
|
ItemName as item_name,
|
|
CONCAT(ItemName,' : ',ItemUnitName) as itemunit_name,
|
|
SupplierPaymentTermsDetailItemUnitID as unit_id,
|
|
ItemUnitName as unit_name,
|
|
0 as qty,
|
|
'N' as is_exist,
|
|
SupplierPaymentTermsDetailPrice as price,
|
|
SupplierPaymentTermsDetailDiscount as discount_percent,
|
|
SupplierPaymentTermsDetailDiscountRp as discount_rp,
|
|
SupplierPaymentTermsDetailTotal as total,
|
|
'N' as selected,
|
|
0 as prepare_detail_id,
|
|
'' as request_number,
|
|
0 as request_receive_id,
|
|
'' as request_branch_name,
|
|
'' as request_company_name
|
|
FROM supplierpaymenttermsdetail
|
|
JOIN item ON SupplierPaymentTermsDetailItemID = ItemID AND ItemIsActive = 'Y'
|
|
JOIN itemunit ON SupplierPaymentTermsDetailItemUnitID = ItemUnitID AND ItemUnitIsActive = 'Y'
|
|
WHERE
|
|
SupplierPaymentTermsSupplierPaymentTermsID = ? AND
|
|
SupplierPaymentTermsDetailIsActive = 'Y'";
|
|
$query = $this->db_inventory->query($sql,$id);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
if($rows && count($rows) > 0){
|
|
foreach ($rows as $key => $value) {
|
|
$rows[$key]['selected'] = false;
|
|
}
|
|
}
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("supplierpaymenttermsdetail rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
}
|
|
else{
|
|
$this->sys_error("Invalid Param ID");
|
|
exit;
|
|
}
|
|
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_prepurchases(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$id = 0;
|
|
if(isset($prm['id']) && intval($prm) > 0){
|
|
$id = $prm['id'];
|
|
$sql = "SELECT PurchasePrepareID as id,
|
|
PurchasePrepareNumber as name
|
|
FROM purchaseprepare
|
|
WHERE
|
|
PurchasePrepareSupplierPaymentTermsID = ? AND
|
|
PurchasePrepareIsActive = 'Y' AND
|
|
PurchasePrepareStatus = 'N'";
|
|
$query = $this->db_inventory->query($sql,$id);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("supplierpaymentterms rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
}
|
|
else{
|
|
$this->sys_error("Invalid Param ID");
|
|
exit;
|
|
}
|
|
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function get_prepurchase_details(){
|
|
try{
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$id = 0;
|
|
if(isset($prm['id']) && intval($prm) > 0){
|
|
$id = $prm['id'];
|
|
$sql = "SELECT PurchasePrepareDetailID as id,
|
|
PurchasePrepareDetailItemID as item_id,
|
|
ItemName as item_name,
|
|
CONCAT(ItemName,' : ',ItemUnitName) as itemunit_name,
|
|
PurchasePrepareDetailItemUnitID as unit_id,
|
|
ItemUnitName as unit_name,
|
|
PurchasePrepareDetailQty as qty,
|
|
'N' as is_exist,
|
|
SupplierPaymentTermsDetailPrice as price,
|
|
SupplierPaymentTermsDetailDiscount as discount_percent,
|
|
SupplierPaymentTermsDetailDiscountRp as discount_rp,
|
|
SupplierPaymentTermsDetailTotal as total,
|
|
'N' as selected,
|
|
PurchasePrepareDetailID as prepare_detail_id,
|
|
GROUP_CONCAT(DISTINCT MutasiRequestReceiveMutasiRequestNumber) as request_number,
|
|
GROUP_CONCAT(MutasiRequestReceiveID) as request_receive_id,
|
|
GROUP_CONCAT( DISTINCT M_BranchName) as request_branch_name,
|
|
GROUP_CONCAT(DISTINCT CompanyName) as request_company_name
|
|
FROM purchasepreparedetail
|
|
JOIN purchaseprepare ON PurchasePrepareDetailPurchasePrepareID = PurchasePrepareID
|
|
JOIN supplierpaymenttermsdetail ON SupplierPaymentTermsSupplierPaymentTermsID = PurchasePrepareSupplierPaymentTermsID AND
|
|
SupplierPaymentTermsDetailIsActive = 'Y'
|
|
JOIN item ON PurchasePrepareDetailItemID = ItemID AND ItemIsActive = 'Y'
|
|
JOIN itemunit ON PurchasePrepareDetailItemUnitID = ItemUnitID AND ItemUnitIsActive = 'Y'
|
|
JOIN purchasepreparedetailrequest ON PurchasePrepareDetailRequestPurchasePrepareDetailID = PurchasePrepareDetailID AND
|
|
PurchasePrepareDetailRequestIsActive = 'Y'
|
|
JOIN mutasirequestreceive ON PurchasePrepareDetailRequestMutasiRequestReceiveID = MutasiRequestReceiveID AND
|
|
MutasiRequestReceiveIsActive = 'Y'
|
|
JOIN companyaddress ON MutasiRequestReceiveCompanyAddressID = CompanyAddressID
|
|
JOIN company ON CompanyAddressCompanyID = CompanyID
|
|
JOIN $this->db_onex.m_branch ON CompanyM_BranchID = M_BranchID
|
|
WHERE
|
|
PurchasePrepareDetailPurchasePrepareID = ? AND
|
|
PurchasePrepareDetailIsActive = 'Y'
|
|
GROUP BY PurchasePrepareDetailID";
|
|
$query = $this->db_inventory->query($sql,$id);
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
if($rows && count($rows) > 0){
|
|
foreach ($rows as $key => $value) {
|
|
$rows[$key]['selected'] = false;
|
|
}
|
|
}
|
|
$result = array("records" => $rows);
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("purchasepreparedetail rows",$this->db_inventory);
|
|
exit;
|
|
}
|
|
}
|
|
else{
|
|
$this->sys_error("Invalid Param ID");
|
|
exit;
|
|
}
|
|
|
|
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
}
|