From 48477e00fd6d4fe6a249ae6af92cfedaba109b76 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 28 May 2017 06:49:17 +0200 Subject: [PATCH] Review payment part on expense report card --- htdocs/expensereport/card.php | 330 +++++++++++++++++++--------------- 1 file changed, 183 insertions(+), 147 deletions(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index fe546cd1064..1dbcbfc1335 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -2,7 +2,7 @@ /* Copyright (C) 2003 Rodolphe Quiedeville * Copyright (C) 2004-2017 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2015-2016 Alexandre Spangaro + * Copyright (C) 2015-2017 Alexandre Spangaro * Copyright (C) 2017 Ferran Marcet * * This program is free software; you can redistribute it and/or modify @@ -37,9 +37,12 @@ require_once DOL_DOCUMENT_ROOT . '/core/lib/expensereport.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/modules/expensereport/modules_expensereport.php'; require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php'; -require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; +require_once DOL_DOCUMENT_ROOT . '/expensereport/class/paymentexpensereport.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; +if (! empty($conf->accounting->enabled)) { + require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php'; +} $langs->load("trips"); $langs->load("bills"); @@ -647,14 +650,14 @@ if (empty($reshook)) { setEventMessages($object->error, $object->errors, 'errors'); } - + if ($action == "confirm_refuse" && GETPOST('confirm')=="yes" && $id > 0 && $user->rights->expensereport->approve) { $object = new ExpenseReport($db); $object->fetch($id); - + $result = $object->setDeny($user,GETPOST('detail_refuse')); - + if ($result > 0) { // Define output language @@ -674,11 +677,11 @@ if (empty($reshook)) $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + if ($result > 0) { // Send mail - + // TO $destinataire = new User($db); $destinataire->fetch($object->fk_user_author); @@ -714,10 +717,10 @@ if (empty($reshook)) array_push($mimetype,"application/pdf"); } */ - + // PREPARE SEND $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); - + if ($mailfile) { // SEND @@ -767,17 +770,17 @@ if (empty($reshook)) { setEventMessages($object->error, $object->errors, 'errors'); } - + //var_dump($user->id == $object->fk_user_validator);exit; if ($action == "confirm_cancel" && GETPOST('confirm')=="yes" && GETPOST('detail_cancel') && $id > 0 && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); $object->fetch($id); - + if ($user->id == $object->fk_user_valid || $user->id == $object->fk_user_author) { $result = $object->set_cancel($user,GETPOST('detail_cancel')); - + if ($result > 0) { // Define output language @@ -797,16 +800,16 @@ if (empty($reshook)) $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + if ($result > 0) { // Send mail - + // TO $destinataire = new User($db); $destinataire->fetch($object->fk_user_author); $emailTo = $destinataire->email; - + // FROM $expediteur = new User($db); $expediteur->fetch($object->fk_user_cancel); @@ -891,7 +894,7 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - + if ($action == "confirm_brouillonner" && GETPOST('confirm')=="yes" && $id > 0 && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); @@ -899,7 +902,7 @@ if (empty($reshook)) if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) { $result = $object->setStatut(0); - + if ($result > 0) { // Define output language @@ -919,7 +922,7 @@ if (empty($reshook)) $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + if ($result > 0) { header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); @@ -935,14 +938,14 @@ if (empty($reshook)) setEventMessages("NOT_AUTHOR", '', 'errors'); } } - + if ($action == 'set_paid' && $id > 0 && $user->rights->expensereport->to_paid) { $object = new ExpenseReport($db); $object->fetch($id); - + $result = $object->set_paid($id, $user); - + if ($result > 0) { // Define output language @@ -962,46 +965,46 @@ if (empty($reshook)) $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - + if ($result > 0) { // Send mail - + // TO $destinataire = new User($db); $destinataire->fetch($object->fk_user_author); $emailTo = $destinataire->email; - + // FROM $expediteur = new User($db); $expediteur->fetch($user->id); $emailFrom = $expediteur->email; - + if ($emailFrom && $emailTo) { $filename=array(); $filedir=array(); $mimetype=array(); // SUBJECT $subject = $langs->transnoentities("ExpenseReportPaid"); - + // CONTENT $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; $message = $langs->transnoentities("ExpenseReportPaidMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link); - + // CONTENT $message = "Bonjour {$destinataire->firstname},\n\n"; $message.= "Votre note de frais \"{$object->ref}\" vient d'être payée.\n"; $message.= "- Payeur : {$expediteur->firstname} {$expediteur->lastname}\n"; $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n"; $message.= "Bien cordialement,\n' SI"; - + // Generate pdf before attachment $object->setDocModel($user,""); $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); - + // PREPARE SEND $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); - + if ($mailfile) { // SEND @@ -1055,45 +1058,44 @@ if (empty($reshook)) if ($action == "addline" && $user->rights->expensereport->creer) { $error = 0; - + $db->begin(); - + $object_ligne = new ExpenseReportLine($db); - + $vatrate = GETPOST('vatrate'); $object_ligne->comments = GETPOST('comments'); $qty = GETPOST('qty','int'); if (empty($qty)) $qty=1; $object_ligne->qty = $qty; - + $up=price2num(GETPOST('value_unit'),'MU'); $object_ligne->value_unit = $up; - + $object_ligne->date = $date; - + $object_ligne->fk_c_type_fees = GETPOST('fk_c_type_fees'); - + // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary. if (empty($vatrate)) $vatrate = "0.000"; $object_ligne->vatrate = price2num($vatrate); - + $object_ligne->fk_projet = $fk_projet; - - + if (! GETPOST('fk_c_type_fees') > 0) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); $action=''; } - + if ($vatrate < 0 || $vatrate == '') { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("VAT")), null, 'errors'); $action=''; } - + /* Projects are never required. To force them, check module forceproject if ($conf->projet->enabled) { @@ -1103,7 +1105,7 @@ if (empty($reshook)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Project")), null, 'errors'); } }*/ - + // Si aucune date n'est rentrée if (empty($object_ligne->date) || $object_ligne->date=="--") { @@ -1116,21 +1118,21 @@ if (empty($reshook)) $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PriceUTTC")), null, 'errors'); } - + // S'il y'a eu au moins une erreur if (! $error) { $object_ligne->fk_expensereport = $_POST['fk_expensereport']; - + $type = 0; // TODO What if service ? $seller = ''; // seller is unknown $tmp = calcul_price_total($qty, $up, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller); - + $object_ligne->vatrate = price2num($vatrate); $object_ligne->total_ttc = $tmp[2]; $object_ligne->total_ht = $tmp[0]; $object_ligne->total_tva = $tmp[1]; - + $result = $object_ligne->insert(); if ($result > 0) { @@ -1144,10 +1146,10 @@ if (empty($reshook)) $db->rollback(); } } - + $action=''; } - + if ($action == 'confirm_delete_line' && GETPOST("confirm") == "yes" && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); @@ -1157,7 +1159,7 @@ if (empty($reshook)) $object_ligne->fetch(GETPOST("rowid")); $total_ht = $object_ligne->total_ht; $total_tva = $object_ligne->total_tva; - + $result=$object->deleteline(GETPOST("rowid"), $user); if ($result >= 0) { @@ -1190,12 +1192,12 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - + if ($action == "updateligne" && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); $object->fetch($id); - + $rowid = $_POST['rowid']; $type_fees_id = GETPOST('fk_c_type_fees'); $projet_id = $fk_projet; @@ -1207,7 +1209,7 @@ if (empty($reshook)) // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary. if (empty($vatrate)) $vatrate = "0.000"; $vatrate = price2num($vatrate); - + if (! GETPOST('fk_c_type_fees') > 0) { $error++; @@ -1220,7 +1222,7 @@ if (empty($reshook)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Vat")), null, 'errors'); $action=''; } - + if (! $error) { // TODO Use update method of ExpenseReportLine @@ -1258,7 +1260,7 @@ if (empty($reshook)) } } } - + // Actions to build doc $upload_dir = $conf->expensereport->dir_output; $permissioncreate = $user->rights->expensereport->creer; @@ -1278,6 +1280,8 @@ $form = new Form($db); $formfile = new FormFile($db); $formproject = new FormProjets($db); $projecttmp = new Project($db); +$paymentexpensereportstatic=new PaymentExpenseReport($db); +$bankaccountstatic = new Account($db); // Create if ($action == 'create') @@ -1320,7 +1324,7 @@ if ($action == 'create') print $s; print ''; print ''; - + print ''; print ''.$langs->trans("VALIDATOR").''; print ''; @@ -1376,7 +1380,7 @@ if ($action == 'create') if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields, 'edit'); } - + print ''; print ''; @@ -1447,7 +1451,7 @@ else $userfee->fetch($object->fk_user_author); print $userfee->getNomUrl(-1); print ''; - + // Ref print ''.$langs->trans("Ref").''; print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', ''); @@ -1542,7 +1546,7 @@ else // Paiement incomplet. On demande si motif = escompte ou autre $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('CloneExpenseReport'), $langs->trans('ConfirmCloneExpenseReport', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); } - + if ($action == 'save') { $formconfirm=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("SaveTrip"),$langs->trans("ConfirmSaveTrip"),"confirm_validate","","",1); @@ -1592,13 +1596,10 @@ else // Print form confirm print $formconfirm; - - + // Expense report card - $linkback = ''.$langs->trans("BackToList").''; - - + $morehtmlref='
'; /* // Ref customer @@ -1639,15 +1640,13 @@ else } }*/ $morehtmlref.='
'; - - + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - - + print '
'; print '
'; print '
'; - + print ''; // Author @@ -1662,7 +1661,7 @@ else print $userauthor->getNomUrl(-1); } print ''; - + print ''; print ''; print ''; } - // Amount - print ''; - print ''; - print ''; - $rowspan = 5; - if ($object->fk_statut < 3) $rowspan++; - elseif($object->fk_statut == 4) $rowspan+=2; - else $rowspan+=2; - if ($object->fk_statut==99 || !empty($object->detail_refuse)) $rowspan+=2; - if($object->fk_statut==6) $rowspan+=2; - print ""; - print ''; - - print ''; - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - print ''; - // Validation date print ''; print ''; @@ -1740,7 +1716,7 @@ else print $userfee->getNomUrl(-1); } print ''; - + print ''; print ''; print ''; @@ -1762,7 +1738,7 @@ else print $userapp->getNomUrl(-1); } print ''; - + print ''; print ''; print ''; @@ -1778,7 +1754,7 @@ else $userfee->fetch($object->fk_user_refuse); print $userfee->getNomUrl(-1); print ''; - + print ''; print ''; print '
'.$langs->trans("Period").''; @@ -1677,29 +1676,6 @@ else print '
'.$langs->trans("AmountHT").''.price($object->total_ht).'
'.$langs->trans("AmountVAT").''.price($object->total_tva).'
'.$langs->trans("AmountTTC").''.price($object->total_ttc).'
'.$langs->trans("DATE_SAVE").'
'.$langs->trans("MOTIF_CANCEL").''.$object->detail_cancel.'
'.$langs->trans("DateApprove").''.dol_print_date($object->date_approve,'dayhour').'
'.$langs->trans("DATE_REFUS").''.dol_print_date($object->date_refuse,'dayhour'); @@ -1805,67 +1781,130 @@ else } // Other attributes - $cols = 3; + $cols = 2; include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; - + print '
'; print '
'; print '
'; print '
'; - //print '
'; - - // List of payments - $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount,"; - $sql.= "c.code as type_code,c.libelle as payment_type"; - $sql.= " FROM ".MAIN_DB_PREFIX."payment_expensereport as p"; + print '
'; + + print ''; + + // Amount + print ''; + print ''; + print ''; + $rowspan = 5; + if ($object->fk_statut < 3) $rowspan++; + elseif($object->fk_statut == 4) $rowspan+=2; + else $rowspan+=2; + if ($object->fk_statut==99 || !empty($object->detail_refuse)) $rowspan+=2; + if($object->fk_statut==6) $rowspan+=2; + print ""; + print ''; + + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + print ''; + + // List of payments already done + $nbcols = 3; + if (! empty($conf->banque->enabled)) { + $nbrows ++; + $nbcols ++; + } + + print '
'.$langs->trans("AmountHT").''.price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency).'
'.$langs->trans("AmountVAT").''.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency).'
'.$langs->trans("AmountTTC").''.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency).'
'; + + print ''; + print ''; + print ''; + print ''; + if (! empty($conf->banque->enabled)) { + print ''; + } + print ''; + print ''; + print ''; + + // Payments already done (from payment on this expensereport) + $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank,"; + $sql.= "c.code as p_code, c.libelle as payment_type,"; + $sql.= "ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal"; + $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as e"; $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c "; - $sql.= ", ".MAIN_DB_PREFIX."expensereport as e"; + $sql.= ", ".MAIN_DB_PREFIX."payment_expensereport as p"; + $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid'; + $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid'; $sql.= " WHERE e.rowid = '".$id."'"; $sql.= " AND p.fk_expensereport = e.rowid"; $sql.= " AND e.entity = ".$conf->entity; $sql.= " AND p.fk_typepayment = c.id"; $sql.= " ORDER BY dp"; - + $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $total = 0; - print '
' . $langs->trans('Payments') . '' . $langs->trans('Date') . '' . $langs->trans('Type') . '' . $langs->trans('BankAccount') . '' . $langs->trans('Amount') . ' 
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - $var=True; while ($i < $num) { $objp = $db->fetch_object($resql); - - print "'; + + print ''; print '\n"; - $labeltype=$langs->trans("PaymentType".$objp->type_code)!=("PaymentType".$objp->type_code)?$langs->trans("PaymentType".$objp->type_code):$objp->fk_typepayment; + $labeltype=$langs->trans("PaymentType".$objp->p_code)!=("PaymentType".$objp->p_code)?$langs->trans("PaymentType".$objp->p_code):$objp->fk_typepayment; print "\n"; - print '\n"; + if (! empty($conf->banque->enabled)) { + $bankaccountstatic->id = $objp->baid; + $bankaccountstatic->ref = $objp->baref; + $bankaccountstatic->label = $objp->baref; + $bankaccountstatic->number = $objp->banumber; + + if (! empty($conf->accounting->enabled)) { + $bankaccountstatic->account_number = $objp->account_number; + + $accountingjournal = new AccountingJournal($db); + $accountingjournal->fetch($objp->fk_accountancy_journal); + $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0,1,1,'',1); + } + + print ''; + } + print '"; print ""; $totalpaid += $objp->amount; $i++; } - + if ($object->paid == 0) { - print "\n"; - print "\n"; + print ''; + print ''; $remaintopay = $object->total_ttc - $totalpaid; - print ""; - print '\n"; + print ''; + print ''; } print "
'.$langs->trans("RefPayment").''.$langs->trans("Date").''.$langs->trans("Type").''.$langs->trans("Amount").' 
"; - print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.'
'; + $paymentexpensereportstatic->id = $objp->rowid; + $paymentexpensereportstatic->datepaye = $db->jdate($objp->dp); + $paymentexpensereportstatic->ref = $objp->rowid; + $paymentexpensereportstatic->num_paiement = $objp->num_paiement; + $paymentexpensereportstatic->payment_code = $objp->payment_code; + print $paymentexpensereportstatic->getNomUrl(1); + print ''.dol_print_date($db->jdate($objp->dp),'day')."".$labeltype.' '.$objp->num_payment."'.price($objp->amount)." ".$langs->trans("Currency".$conf->currency)."'; + if ($bankaccountstatic->id) + print $bankaccountstatic->getNomUrl(1, 'transactions'); + print ''.price($objp->amount)."
".$langs->trans("AlreadyPaid")." :".price($totalpaid)."
".$langs->trans("AmountExpected")." :".price($object->total_ttc)."
'.$langs->trans("AlreadyPaid").':'.price($totalpaid).'
'.$langs->trans("AmountExpected").':'.price($object->total_ttc).'
".$langs->trans("RemainderToPay")." :'.price($remaintopay)."
'.$langs->trans("RemainderToPay").':'.price($remaintopay).'
"; $db->free($resql); @@ -1873,15 +1912,13 @@ else else { dol_print_error($db); - } - + } + print '
'; print '
'; print '
'; - + print '

'; - - print '
'; // Fetch Lines of current expense report $sql = 'SELECT fde.rowid, fde.fk_expensereport, fde.fk_c_type_fees, fde.fk_projet, fde.date,'; @@ -1898,18 +1935,17 @@ else $actiontouse='updateligne'; if (($object->fk_statut==0 || $object->fk_statut==99) && $action != 'editline') $actiontouse='addline'; - + print '
'; print ''; print ''; print ''; print ''; - - + print '
'; print ''; - - $resql = $db->query($sql); + + $resql = $db->query($sql); if ($resql) { $num_lignes = $db->num_rows($resql); @@ -1989,7 +2025,7 @@ else print ''; } - + print ''; } @@ -2042,7 +2078,7 @@ else print ''; print ''; } - + print ''; print ''; - + print ''; print ''; - + // Select date print ''; + print ''; } - + // Select type print '
'.$langs->trans('AmountHT').''.$langs->trans('AmountTTC').''; print ''; print ''; @@ -2078,11 +2114,11 @@ else print '
'; $form->select_date($date?$date:-1,'date'); @@ -2091,11 +2127,11 @@ else // Select project if (! empty($conf->projet->enabled)) { - print ''; - $formproject->select_projects(-1, $fk_projet, 'fk_projet', 0, 0, 1, 1); - print ''; + $formproject->select_projects(-1, $fk_projet, 'fk_projet', 0, 0, 1, 1); + print ''; select_type_fees_id($fk_c_type_fees,'fk_c_type_fees',1); @@ -2249,7 +2285,7 @@ if ($action != 'create' && $action != 'edit') } } - + // If status is Appoved // -------------------- @@ -2257,7 +2293,7 @@ if ($action != 'create' && $action != 'edit') { print ''; } - + // If bank module is used if ($user->rights->expensereport->to_paid && ! empty($conf->banque->enabled) && $object->fk_statut == 5) { @@ -2272,7 +2308,7 @@ if ($action != 'create' && $action != 'edit') } } - // If bank module is not used + // If bank module is not used if (($user->rights->expensereport->to_paid || empty($conf->banque->enabled)) && $object->fk_statut == 5) { //if ((round($remaintopay) == 0 || empty($conf->banque->enabled)) && $object->paid == 0)