Bill Hook file
================
<?php
// For help on using hooks, please refer to
https://bigprof.com/appgini/help/workin ... tion/hooks
function Bill_init(&$options, $memberInfo, &$args){
// modify the PAYMENT_STATUS field of the table view query to display 'Due' invoices in bold red
$oldArray=$options->QueryFieldsTV;
$options->QueryFieldsTV='';
foreach($oldArray as $field => $caption){
if($field=='`Bill`.`PAYMENT_STATUS`'){
$options->QueryFieldsTV['IF(`Bill`.`PAYMENT_STATUS`=\'PAID\', \'<b style="color: yellow;">PAID</b>\', IF(`Bill`.`PAYMENT_STATUS`=\'DUE\', \'<b style="color: red;">DUE</b>\', `Bill`.`PAYMENT_STATUS`))']=$caption;
}else{
$options->QueryFieldsTV[$field]=$caption;
}
}
return TRUE;
}
function Bill_header($contentType, $memberInfo, &$args){
$header='';
switch($contentType){
case 'tableview':
$header='';
break;
case 'detailview':
$header='';
break;
case 'tableview+detailview':
$header='';
break;
case 'print-tableview':
$header='';
break;
case 'print-detailview':
$header='';
break;
case 'filters':
$header='';
break;
}
return $header;
}
function Bill_footer($contentType, $memberInfo, &$args){
$footer='';
switch($contentType){
case 'tableview':
$footer='';
break;
case 'detailview':
$footer='';
break;
case 'tableview+detailview':
$footer='';
break;
case 'print-tableview':
$footer='';
break;
case 'print-detailview':
$footer='';
break;
case 'filters':
$footer='';
break;
}
return $footer;
}
function Bill_before_insert(&$data, $memberInfo, &$args){
$data['due_taka'] = $data['total'] - $data['nogot_joma'];
return TRUE;
}
function Bill_after_insert($data, $memberInfo, &$args){
update_balances($data);
return TRUE;
}
function Bill_before_update(&$data, $memberInfo, &$args){
$data['due_taka'] = $data['total'] - $data['nogot_joma'];
return TRUE;
}
function Bill_after_update($data, $memberInfo, &$args){
update_balances($data);
return TRUE;
}
function Bill_before_delete($selectedID, &$skipChecks, $memberInfo, &$args){
$res = sql("select * from Bill where id='{$selectedID}'", $eo);
$GLOBALS['deleted_data'] = db_fetch_assoc($res);
return TRUE;
}
function Bill_after_delete($selectedID, $memberInfo, &$args){
update_balances($GLOBALS['deleted_data']);
}
function Bill_dv($selectedID, $memberInfo, &$html, &$args){
}
function Bill_csv($query, $memberInfo, &$args){
return $query;
}
function Bill_batch_actions(&$args){
return array();
}
function transactions_batch_actions(&$args){
return array();
}
function update_balances($data){
$ACCOUNT_NAME = intval($data['ACCOUNT_NAME']);
/*
Comma-separated list of all transaction types (each enclosed in single quotes) that add
to inventory -- others are assumed to subtract from inventory
*/
$positive_transactions = "'PAID,DUE'";
/* get sum of all ACCOUNT_NAME funded_transaction and update ACCOUNT_NAME BALANCE */
/* get sum of all item transactions and update item balance */
if($ACCOUNT_NAME){
$ACCOUNT_NAME_balance = sqlValue("select sum(if(PAYMENT_STATUS in ({$positive_transactions}), nogot_joma, 1 * nogot_joma)) from Bill where ACCOUNT_NAME={$ACCOUNT_NAME}");
sql("update cash_book set balance='{$ACCOUNT_NAME_balance}' where id={$ACCOUNT_NAME}", $eo);
include('dbcon.php');
$query=mysql_query("select * from cash_book where id={$ACCOUNT_NAME} ")or die(mysql_error());
$row=mysql_fetch_array($query);
$ALANCE=$row['balance']- $row['expense'];
sql("UPDATE cash_book SET total_balance= '{$ALANCE}' where id={$ACCOUNT_NAME}", $eo);
}
/* get sum of all item pur and update item balance */
/* get sum of all ACCOUNT_NAME funded_transaction and update ACCOUNT_NAME BALANCE */
/* get sum of all ACCOUNT_NAME funded_transaction and update ACCOUNT_NAME BALANCE */
}