From 98b952b54700404482a189152e5e9f2dfc44d276 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 27 Mar 2018 12:09:34 +0200 Subject: [PATCH] FIX Create payment of expense report --- .../class/paymentexpensereport.class.php | 6 ++-- htdocs/expensereport/payment/payment.php | 29 +++++++++++-------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/htdocs/expensereport/class/paymentexpensereport.class.php b/htdocs/expensereport/class/paymentexpensereport.class.php index e269d9c7c3e..0634ca16b7a 100644 --- a/htdocs/expensereport/class/paymentexpensereport.class.php +++ b/htdocs/expensereport/class/paymentexpensereport.class.php @@ -92,6 +92,7 @@ class PaymentExpenseReport extends CommonObject if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); + if (! empty($this->fk_expensereport)) $this->chid = $this->fk_expensereport; $totalamount = 0; foreach ($this->amounts as $key => $value) // How payment is dispatch @@ -108,9 +109,6 @@ class PaymentExpenseReport extends CommonObject $this->db->begin(); - //Fix me fields - $this->chid = $this->fk_expensereport; - if ($totalamount != 0) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_expensereport (fk_expensereport, datec, datep, amount,"; @@ -515,7 +513,7 @@ class PaymentExpenseReport extends CommonObject //Fix me field $this->total = $this->amount; $total = $this->total; - + if ($mode == 'payment_expensereport') $amount=$total; // Insert payment into llx_bank diff --git a/htdocs/expensereport/payment/payment.php b/htdocs/expensereport/payment/payment.php index ad74c7fda05..84cf798285d 100644 --- a/htdocs/expensereport/payment/payment.php +++ b/htdocs/expensereport/payment/payment.php @@ -31,7 +31,7 @@ $langs->load("bills"); $langs->load("banks"); $langs->load("trips"); -$chid=GETPOST("id",'int'); +$id=GETPOST("id",'int'); $ref=GETPOST('ref','alpha'); $action=GETPOST('action','aZ09'); $amounts = array(); @@ -55,13 +55,18 @@ if ($action == 'add_payment') if ($_POST["cancel"]) { - $loc = DOL_URL_ROOT.'/expensereport/card.php?id='.$chid; + $loc = DOL_URL_ROOT.'/expensereport/card.php?id='.$id; header("Location: ".$loc); exit; } $expensereport = new ExpenseReport($db); - $expensereport->fetch($chid, $ref); + $result = $expensereport->fetch($id, $ref); + if (! $result) + { + $error++; + setEventMessages($expensereport->error, $expensereport->errors, 'errors'); + } $datepaid = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); @@ -108,7 +113,7 @@ if ($action == 'add_payment') // Create a line of payments $payment = new PaymentExpenseReport($db); - $payment->chid = $chid; + $payment->chid = $expensereport->id; $payment->datepaid = $datepaid; $payment->amounts = $amounts; // Tableau de montant $payment->total = $total; @@ -121,7 +126,7 @@ if ($action == 'add_payment') $paymentid = $payment->create($user); if ($paymentid < 0) { - $errmsg=$payment->error; + setEventMessages($payment->error, $payment->errors, 'errors'); $error++; } } @@ -131,7 +136,7 @@ if ($action == 'add_payment') $result=$payment->addPaymentToBank($user,'payment_expensereport','(ExpenseReportPayment)',$accountid,'',''); if (! $result > 0) { - $errmsg=$payment->error; + setEventMessages($payment->error, $payment->errors, 'errors'); $error++; } } @@ -141,7 +146,7 @@ if ($action == 'add_payment') if ($expensereport->total_ttc - $payment->amount == 0) { $result = $expensereport->set_paid($expensereport->id, $user); if (!$result > 0) { - $errmsg = $payment->error; + setEventMessages($payment->error, $payment->errors, 'errors'); $error++; } } @@ -151,7 +156,7 @@ if ($action == 'add_payment') if (! $error) { $db->commit(); - $loc = DOL_URL_ROOT.'/expensereport/card.php?id='.$chid; + $loc = DOL_URL_ROOT.'/expensereport/card.php?id='.$id; header('Location: '.$loc); exit; } @@ -179,7 +184,7 @@ $form=new Form($db); if ($action == 'create' || empty($action)) { $expensereport = new ExpenseReport($db); - $expensereport->fetch($chid, $ref); + $expensereport->fetch($id, $ref); $total = $expensereport->total_ttc; @@ -187,8 +192,8 @@ if ($action == 'create' || empty($action)) print '
'; print ''; - print ''; - print ''; + print ''; + print ''; print ''; dol_fiche_head(null, '0', '', -1); @@ -208,7 +213,7 @@ if ($action == 'create' || empty($action)) $sql = "SELECT sum(p.amount) as total"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_expensereport as p, ".MAIN_DB_PREFIX."expensereport as e"; - $sql.= " WHERE p.fk_expensereport = e.rowid AND p.fk_expensereport = ".$chid; + $sql.= " WHERE p.fk_expensereport = e.rowid AND p.fk_expensereport = ".$id; $sql.= ' AND e.entity IN ('.getEntity('expensereport').')'; $resql = $db->query($sql); if ($resql)