FIX Create payment of expense report

This commit is contained in:
Laurent Destailleur 2018-03-27 12:09:34 +02:00
parent 2e296b3475
commit 98b952b547
2 changed files with 19 additions and 16 deletions

View File

@ -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

View File

@ -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 '<form name="add_payment" action="'.$_SERVER['PHP_SELF'].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="id" value="'.$chid.'">';
print '<input type="hidden" name="chid" value="'.$chid.'">';
print '<input type="hidden" name="id" value="'.$expensereport->id.'">';
print '<input type="hidden" name="chid" value="'.$expensereport->id.'">';
print '<input type="hidden" name="action" value="add_payment">';
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)