Skip to content

Commit

Permalink
Messed in Employee Advance allocating: Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
notrinos committed Nov 3, 2020
1 parent 53094d2 commit b1c2a4f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 46 deletions.
4 changes: 3 additions & 1 deletion includes/ui/employee_bank_ui.inc
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@ function display_bank_gl_items($title, &$order) {
gl_edit_item_controls($order, $dim, $line);
}

if($order->count_gl_items())
if($order->count_gl_items()) {
label_row(_('Total'), number_format2(abs($order->gl_items_total()), user_price_dec()), 'colspan='.$colspan." align=right", "align=right id='payment_total_amt'", 3);
hidden('total_payments', $order->gl_items_total());
}

end_table();
div_end();
Expand Down
30 changes: 17 additions & 13 deletions js/emp_payalloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ function blur_alloc(i) {
var change = get_amount(i.name);
payment_amt = get_amount('item_amount', true);

if (i.name != 'amount' && i.name != 'charge' && i.name != 'discount')
if(i.name != 'amount' && i.name != 'charge' && i.name != 'discount')
change = Math.min(change, get_amount('maxval'+i.name.substr(6), 1))

price_format(i.name, change, user.pdec);
if (i.name != 'amount' && i.name != 'charge') {
if (change<0) change = 0;
change = change-i.getAttribute('_last');
if (i.name == 'discount') change = -change;

if(i.name != 'amount' && i.name != 'charge') {

if(change < 0)
change = 0;

change = change - i.getAttribute('_last');

if(i.name == 'discount')
change = -change;

var total = get_amount('amount')+change;
price_format('amount', total, user.pdec, 0);
Expand All @@ -35,7 +41,7 @@ function emp_allocate_all(doc) {
var unallocated = get_amount('un_allocated'+doc);
var total = get_amount('amount', true);
var gl_payments = document.getElementById('item_amount');
var payment_amt = gl_payments == null ? 0 : get_amount('item_amount', true);
var payment_amt = get_amount('total_payments');
var left = 0;
total -= (amount-unallocated);
left -= (amount-unallocated);
Expand All @@ -47,13 +53,11 @@ function emp_allocate_all(doc) {
left = 0;
}

if(gl_payments != null) {
price_format('amount'+doc, amount, user.pdec);
price_format('amount', total, user.pdec);
price_format('amount', total, user.pdec, 'amount');
price_format('item_amount', payment_amt - amount, user.pdec, 'item_amount');
price_format('payment_total_amt', parseFloat(payment_amt) - amount, user.pdec, 'payment_total_amt');
}
price_format('amount'+doc, amount, user.pdec);
price_format('amount', total, user.pdec);
price_format('amount', total, user.pdec, 'amount');
price_format('item_amount', payment_amt - total, user.pdec, 'item_amount');
price_format('payment_total_amt', parseFloat(payment_amt) - total, user.pdec, 'payment_total_amt');
}

function emp_allocate_none(doc) {
Expand Down
63 changes: 31 additions & 32 deletions manage/employee_bank_entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
include_once($path_to_root . '/admin/db/attachments_db.inc');

$js = '';
if ($SysPrefs->use_popup_windows)

if($SysPrefs->use_popup_windows)
$js .= get_js_open_window(800, 500);
if (user_use_date_picker())
if(user_use_date_picker())
$js .= get_js_date_picker();
add_js_file('payalloc.js');
add_js_ufile($path_to_root.'/modules/FrontHrm/js/emp_payalloc.js');

if (isset($_GET['NewPayment'])) {
if(isset($_GET['NewPayment'])) {
$_SESSION['page_title'] = _($help_context = 'Employee Payment Entry');
create_cart(ST_BANKPAYMENT, 0);
}
Expand All @@ -56,7 +57,7 @@

page($_SESSION['page_title'], false, false, '', $js);

if (isset($_GET['PayslipNo'])) {
if(isset($_GET['PayslipNo'])) {

if(has_payment_advice($_GET['PayslipNo'])) {

Expand All @@ -81,12 +82,12 @@

check_db_has_bank_accounts(_('There are no bank accounts defined in the system.'));

if (isset($_GET['ModifyDeposit']) || isset($_GET['ModifyPayment']))
if(isset($_GET['ModifyDeposit']) || isset($_GET['ModifyPayment']))
check_is_editable($_SESSION['pay_items']->trans_type, $_SESSION['pay_items']->order_id);

//--------------------------------------------------------------------------------------------------

if (list_updated('PersonDetailID')) {
if(list_updated('PersonDetailID')) {
$br = get_branch(get_post('PersonDetailID'));
$_POST['person_id'] = $br['debtor_no'];
$Ajax->activate('person_id');
Expand All @@ -103,7 +104,7 @@ function line_start_focus() {

//--------------------------------------------------------------------------------------------------

if (isset($_GET['AddedID'])) {
if(isset($_GET['AddedID'])) {
$trans_no = $_GET['AddedID'];
$trans_type = ST_BANKPAYMENT;
$payslip_no = get_payslip_from_advice($trans_no)['payslip_no'];
Expand All @@ -124,7 +125,7 @@ function line_start_focus() {
display_footer_exit();
}

if (isset($_GET['UpdatedID'])) {
if(isset($_GET['UpdatedID'])) {
$trans_no = $_GET['UpdatedID'];
$trans_type = ST_BANKPAYMENT;

Expand All @@ -138,8 +139,7 @@ function line_start_focus() {

display_footer_exit();
}

if (isset($_GET['AddedDep'])) {
if(isset($_GET['AddedDep'])) {
$trans_no = $_GET['AddedDep'];
$trans_type = ST_BANKDEPOSIT;

Expand All @@ -153,7 +153,7 @@ function line_start_focus() {

display_footer_exit();
}
if (isset($_GET['UpdatedDep'])) {
if(isset($_GET['UpdatedDep'])) {
$trans_no = $_GET['UpdatedDep'];
$trans_type = ST_BANKDEPOSIT;

Expand All @@ -173,30 +173,30 @@ function line_start_focus() {
function create_cart($type, $trans_no, $payslip=array()) {
global $Refs, $Payable_act;

if (isset($_SESSION['pay_items']))
if(isset($_SESSION['pay_items']))
unset ($_SESSION['pay_items']);

$cart = new items_cart($type);
$cart->order_id = $trans_no;

if ($trans_no) {
if($trans_no) {

$bank_trans = db_fetch(get_bank_trans($type, $trans_no));
$_POST['bank_account'] = $bank_trans['bank_act'];
$_POST['PayType'] = $bank_trans['person_type_id'];
$cart->reference = $bank_trans['ref'];

if ($bank_trans['person_type_id'] == PT_MISC)
if($bank_trans['person_type_id'] == PT_MISC)
$_POST['person_id'] = $bank_trans['person_id'];

$cart->memo_ = get_comments_string($type, $trans_no);
$cart->tran_date = sql2date($bank_trans['trans_date']);

$cart->original_amount = $bank_trans['amount'];
$result = get_gl_trans($type, $trans_no);
if ($result) {
if($result) {
while ($row = db_fetch($result)) {
if (is_bank_account($row['account']))
if(is_bank_account($row['account']))
$ex_rate = $bank_trans['amount'] / $row['amount'];
else
$cart->add_gl_item( $row['account'], $row['dimension_id'], $row['dimension2_id'], $row['amount'], $row['memo_']);
Expand All @@ -209,7 +209,7 @@ function create_cart($type, $trans_no, $payslip=array()) {
else {
$cart->reference = $Refs->get_next($cart->trans_type, null, $cart->tran_date);
$cart->tran_date = new_doc_date();
if (!is_date_in_fiscalyear($cart->tran_date))
if(!is_date_in_fiscalyear($cart->tran_date))
$cart->tran_date = end_fiscalyear();
}

Expand All @@ -220,11 +220,8 @@ function create_cart($type, $trans_no, $payslip=array()) {
$_POST['emp_id'] = $cart->person_id;
$_POST['for_payslip'] = $cart->payslip_no;
$cart->memo_ = _('Payment advice gl entry For Payslip #').$cart->payslip_no;

$pay_amt = $payslip['payable_amount'];

$bank = get_default_bank_account();

$_POST['bank_account'] = $bank['id'];

$cart->add_gl_item($Payable_act, 0, 0, $pay_amt, '');
Expand Down Expand Up @@ -327,7 +324,7 @@ function check_trans() {
}
}

if (isset($_POST['Process']) && !check_trans()) {
if(isset($_POST['Process']) && !check_trans()) {
begin_transaction();

$_SESSION['pay_items'] = &$_SESSION['pay_items'];
Expand Down Expand Up @@ -419,7 +416,7 @@ function handle_delete_item($id) {
}

function handle_new_item() {
if (!check_item_data())
if(!check_item_data())
return;
$amount = ($_SESSION['pay_items']->trans_type==ST_BANKPAYMENT ? 1:-1) * input_num('amount');
$_SESSION['pay_items']->add_gl_item($_POST['code_id'], $_POST['dimension_id'], $_POST['dimension2_id'], $amount, $_POST['LineMemo']);
Expand Down Expand Up @@ -454,18 +451,20 @@ function handle_new_item() {
br();
}

if(!empty($_POST['emp_id']) && empty($_POST['NewAdvance']))
show_employee_advances($_POST['emp_id']);
if($_SESSION['pay_items']->count_gl_items() > 0) {

start_table(TABLESTYLE2, "width='90%'", 10);
start_row();
echo "<td>";
if($_SESSION['pay_items']->count_gl_items() > 0)
if(!empty($_POST['emp_id']) && empty($_POST['NewAdvance']))
show_employee_advances($_POST['emp_id']);

start_table(TABLESTYLE2, "width='90%'", 10);
start_row();
echo "<td>";
display_bank_gl_items($_SESSION['pay_items']->trans_type==ST_BANKPAYMENT ? _("Payment Items"):_("Deposit Items"), $_SESSION['pay_items']);
gl_options_controls($_SESSION['pay_items']);
echo "</td>";
end_row();
end_table(1);
gl_options_controls($_SESSION['pay_items']);
echo "</td>";
end_row();
end_table(1);
}

submit_center_first('Update', _('Update'), '', null);
if($_SESSION['pay_items']->count_gl_items() > 0)
Expand Down

0 comments on commit b1c2a4f

Please sign in to comment.