|
@@ -26,6 +26,7 @@
|
|
|
require '../main.inc.php';
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
|
|
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
|
|
+require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
|
|
|
|
|
|
$langs->load("orders");
|
|
@@ -92,6 +93,12 @@ if ($action == 'confirm_split' && GETPOST("confirm") == 'yes')
|
|
|
$newdiscount2->fk_facture=$discount->fk_facture;
|
|
|
$newdiscount1->fk_facture_line=$discount->fk_facture_line;
|
|
|
$newdiscount2->fk_facture_line=$discount->fk_facture_line;
|
|
|
+ $newdiscount1->fk_invoice_supplier_source=$discount->fk_invoice_supplier_source;
|
|
|
+ $newdiscount2->fk_invoice_supplier_source=$discount->fk_invoice_supplier_source;
|
|
|
+ $newdiscount1->fk_invoice_supplier=$discount->fk_invoice_supplier;
|
|
|
+ $newdiscount2->fk_invoice_supplier=$discount->fk_invoice_supplier;
|
|
|
+ $newdiscount1->fk_invoice_supplier_line=$discount->fk_invoice_supplier_line;
|
|
|
+ $newdiscount2->fk_invoice_supplier_line=$discount->fk_invoice_supplier_line;
|
|
|
if ($discount->description == '(CREDIT_NOTE)' || $discount->description == '(DEPOSIT)')
|
|
|
{
|
|
|
$newdiscount1->description=$discount->description;
|
|
@@ -106,6 +113,8 @@ if ($action == 'confirm_split' && GETPOST("confirm") == 'yes')
|
|
|
$newdiscount2->fk_user=$discount->fk_user;
|
|
|
$newdiscount1->fk_soc=$discount->fk_soc;
|
|
|
$newdiscount2->fk_soc=$discount->fk_soc;
|
|
|
+ $newdiscount1->discount_type=$discount->discount_type;
|
|
|
+ $newdiscount2->discount_type=$discount->discount_type;
|
|
|
$newdiscount1->datec=$discount->datec;
|
|
|
$newdiscount2->datec=$discount->datec;
|
|
|
$newdiscount1->tva_tx=$discount->tva_tx;
|
|
@@ -143,6 +152,7 @@ if ($action == 'setremise' && $user->rights->societe->creer)
|
|
|
$amount_ht=GETPOST('amount_ht');
|
|
|
$desc=GETPOST('desc','alpha');
|
|
|
$tva_tx=GETPOST('tva_tx','alpha');
|
|
|
+ $discount_type=! empty($_POST['discount_type'])?GETPOST('discount_type','alpha'):0;
|
|
|
|
|
|
if (price2num($amount_ht) > 0)
|
|
|
{
|
|
@@ -157,7 +167,7 @@ if ($action == 'setremise' && $user->rights->societe->creer)
|
|
|
{
|
|
|
$soc = new Societe($db);
|
|
|
$soc->fetch($id);
|
|
|
- $discountid=$soc->set_remise_except($amount_ht,$user,$desc,$tva_tx);
|
|
|
+ $discountid=$soc->set_remise_except($amount_ht,$user,$desc,$tva_tx,$discount_type);
|
|
|
|
|
|
if ($discountid > 0)
|
|
|
{
|
|
@@ -215,6 +225,7 @@ if (GETPOST('action','aZ09') == 'confirm_remove' && GETPOST("confirm")=='yes')
|
|
|
|
|
|
$form=new Form($db);
|
|
|
$facturestatic=new Facture($db);
|
|
|
+$facturefournstatic=new FactureFournisseur($db);
|
|
|
|
|
|
llxHeader('',$langs->trans("GlobalDiscount"));
|
|
|
|
|
@@ -224,12 +235,14 @@ if ($socid > 0)
|
|
|
$object = new Societe($db);
|
|
|
$object->fetch($socid);
|
|
|
|
|
|
+ $isCustomer = $object->client == 1 || $object->client == 3;
|
|
|
+ $isSupplier = $object->fournisseur == 1;
|
|
|
+
|
|
|
/*
|
|
|
* Display tabs
|
|
|
*/
|
|
|
$head = societe_prepare_head($object);
|
|
|
|
|
|
-
|
|
|
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
|
|
|
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
|
|
print '<input type="hidden" name="action" value="setremise">';
|
|
@@ -242,36 +255,85 @@ if ($socid > 0)
|
|
|
print '<div class="fichecenter">';
|
|
|
|
|
|
print '<div class="underbanner clearboth"></div>';
|
|
|
+
|
|
|
+ if(! $isCustomer && ! $isSupplier) {
|
|
|
+ print '<p class="opacitymedium">'.$langs->trans('ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').'</p>';
|
|
|
+
|
|
|
+ dol_fiche_end();
|
|
|
+
|
|
|
+ print '</form>';
|
|
|
+
|
|
|
+ llxFooter();
|
|
|
+ $db->close();
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
print '<table class="border centpercent">';
|
|
|
|
|
|
- // Calcul avoirs en cours
|
|
|
- $remise_all=$remise_user=0;
|
|
|
- $sql = "SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
|
|
|
- $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
|
|
|
- $sql.= " WHERE rc.fk_soc = " . $object->id;
|
|
|
- $sql.= " AND rc.entity = " . $conf->entity;
|
|
|
- $sql.= " AND (fk_facture_line IS NULL AND fk_facture IS NULL)";
|
|
|
- $sql.= " GROUP BY rc.fk_user";
|
|
|
- $resql=$db->query($sql);
|
|
|
- if ($resql)
|
|
|
- {
|
|
|
- $obj = $db->fetch_object($resql);
|
|
|
- $remise_all+=$obj->amount;
|
|
|
- if ($obj->fk_user == $user->id) $remise_user+=$obj->amount;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- dol_print_error($db);
|
|
|
- }
|
|
|
+ if($isCustomer) { // Calcul avoirs client en cours
|
|
|
+ $remise_all=$remise_user=0;
|
|
|
+ $sql = "SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
|
|
|
+ $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
|
|
|
+ $sql.= " WHERE rc.fk_soc = " . $object->id;
|
|
|
+ $sql.= " AND rc.entity = " . $conf->entity;
|
|
|
+ $sql.= " AND discount_type = 0"; // Exclude supplier discounts
|
|
|
+ $sql.= " AND (fk_facture_line IS NULL AND fk_facture IS NULL)";
|
|
|
+ $sql.= " GROUP BY rc.fk_user";
|
|
|
+ $resql=$db->query($sql);
|
|
|
+ if ($resql)
|
|
|
+ {
|
|
|
+ $obj = $db->fetch_object($resql);
|
|
|
+ $remise_all+=$obj->amount;
|
|
|
+ if ($obj->fk_user == $user->id) $remise_user+=$obj->amount;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dol_print_error($db);
|
|
|
+ }
|
|
|
|
|
|
- print '<tr><td class="titlefield">'.$langs->trans("CustomerAbsoluteDiscountAllUsers").'</td>';
|
|
|
- print '<td>'.$remise_all.' '.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").'</td></tr>';
|
|
|
+ print '<tr><td class="titlefield">'.$langs->trans("CustomerAbsoluteDiscountAllUsers").'</td>';
|
|
|
+ print '<td>'.$remise_all.' '.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").'</td></tr>';
|
|
|
+
|
|
|
+ if (! empty($user->fk_soc)) // No need to show this for external users
|
|
|
+ {
|
|
|
+ print '<tr><td>'.$langs->trans("CustomerAbsoluteDiscountMy").'</td>';
|
|
|
+ print '<td>'.$remise_user.' '.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").'</td></tr>';
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (! empty($user->fk_soc)) // No need to show this for external users
|
|
|
- {
|
|
|
- print '<tr><td>'.$langs->trans("CustomerAbsoluteDiscountMy").'</td>';
|
|
|
- print '<td>'.$remise_user.' '.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").'</td></tr>';
|
|
|
+ if($isSupplier) {
|
|
|
+ // Calcul avoirs fournisseur en cours
|
|
|
+ $remise_all=$remise_user=0;
|
|
|
+ $sql = "SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
|
|
|
+ $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
|
|
|
+ $sql.= " WHERE rc.fk_soc = " . $object->id;
|
|
|
+ $sql.= " AND rc.entity = " . $conf->entity;
|
|
|
+ $sql.= " AND discount_type = 1"; // Exclude customer discounts
|
|
|
+ $sql.= " AND (fk_invoice_supplier_line IS NULL AND fk_invoice_supplier IS NULL)";
|
|
|
+ $sql.= " GROUP BY rc.fk_user";
|
|
|
+ $resql=$db->query($sql);
|
|
|
+ if ($resql)
|
|
|
+ {
|
|
|
+ $obj = $db->fetch_object($resql);
|
|
|
+ $remise_all+=$obj->amount;
|
|
|
+ if ($obj->fk_user == $user->id) $remise_user+=$obj->amount;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dol_print_error($db);
|
|
|
+ }
|
|
|
+
|
|
|
+ print '<tr><td class="titlefield">'.$langs->trans("SupplierAbsoluteDiscountAllUsers").'</td>';
|
|
|
+ print '<td>'.$remise_all.' '.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").'</td></tr>';
|
|
|
+
|
|
|
+ if (! empty($user->fk_soc)) // No need to show this for external users
|
|
|
+ {
|
|
|
+ print '<tr><td>'.$langs->trans("SupplierAbsoluteDiscountMy").'</td>';
|
|
|
+ print '<td>'.$remise_user.' '.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").'</td></tr>';
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
print '</table>';
|
|
|
|
|
|
print '</div>';
|
|
@@ -283,7 +345,22 @@ if ($socid > 0)
|
|
|
print load_fiche_titre($langs->trans("NewGlobalDiscount"),'','');
|
|
|
|
|
|
print '<div class="underbanner clearboth"></div>';
|
|
|
+
|
|
|
+ if($isCustomer && ! $isSupplier) {
|
|
|
+ print '<input type="hidden" name="discount_type" value="0" />';
|
|
|
+ }
|
|
|
+
|
|
|
+ if(! $isCustomer && $isSupplier) {
|
|
|
+ print '<input type="hidden" name="discount_type" value="1" />';
|
|
|
+ }
|
|
|
+
|
|
|
print '<table class="border" width="100%">';
|
|
|
+ if($isCustomer && $isSupplier) {
|
|
|
+ print '<tr><td class="titlefield fieldrequired">'.$langs->trans('DiscountType').'</td>';
|
|
|
+ print '<td><input type="radio" name="discount_type" id="discount_type_0" selected value="0"/> <label for="discount_type_0">'.$langs->trans('Customer').'</label>';
|
|
|
+ print ' <input type="radio" name="discount_type" id="discount_type_1" selected value="1"/> <label for="discount_type_1">'.$langs->trans('Supplier').'</label>';
|
|
|
+ print '</td></tr>';
|
|
|
+ }
|
|
|
print '<tr><td class="titlefield fieldrequired">'.$langs->trans("AmountHT").'</td>';
|
|
|
print '<td><input type="text" size="5" name="amount_ht" value="'.price2num(GETPOST("amount_ht")).'">';
|
|
|
print '<span class="hideonsmartphone"> '.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
|
|
@@ -321,132 +398,287 @@ if ($socid > 0)
|
|
|
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&remid='.GETPOST('remid'), $langs->trans('RemoveDiscount'), $langs->trans('ConfirmRemoveDiscount'), 'confirm_remove', '', 0, 1);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/*
|
|
|
- * Liste remises fixes restant en cours (= liees a aucune facture ni ligne de facture)
|
|
|
+ * Liste remises fixes client restant en cours (= liees a aucune facture ni ligne de facture)
|
|
|
*/
|
|
|
- $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
|
|
|
- $sql.= " rc.datec as dc, rc.description,";
|
|
|
- $sql.= " rc.fk_facture_source,";
|
|
|
- $sql.= " u.login, u.rowid as user_id,";
|
|
|
- $sql.= " fa.facnumber as ref, fa.type as type";
|
|
|
- $sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."societe_remise_except as rc";
|
|
|
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
|
|
|
- $sql.= " WHERE rc.fk_soc = " . $object->id;
|
|
|
- $sql.= " AND rc.entity = " . $conf->entity;
|
|
|
- $sql.= " AND u.rowid = rc.fk_user";
|
|
|
- $sql.= " AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL)";
|
|
|
- $sql.= " ORDER BY rc.datec DESC";
|
|
|
-
|
|
|
- $resql=$db->query($sql);
|
|
|
- if ($resql)
|
|
|
- {
|
|
|
- print load_fiche_titre($langs->trans("DiscountStillRemaining"));
|
|
|
- print '<table width="100%" class="noborder">';
|
|
|
- print '<tr class="liste_titre">';
|
|
|
- print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
|
|
|
- print '<td>'.$langs->trans("ReasonDiscount").'</td>';
|
|
|
- print '<td width="150" class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
|
|
|
- print '<td width="120" align="right">'.$langs->trans("AmountHT").'</td>';
|
|
|
- print '<td width="80" align="right">'.$langs->trans("VATRate").'</td>';
|
|
|
- print '<td width="120" align="right">'.$langs->trans("AmountTTC").'</td>';
|
|
|
- print '<td width="100" align="center">'.$langs->trans("DiscountOfferedBy").'</td>';
|
|
|
- print '<td width="50"> </td>';
|
|
|
- print '</tr>';
|
|
|
-
|
|
|
- $showconfirminfo=array();
|
|
|
-
|
|
|
- $i = 0;
|
|
|
- $num = $db->num_rows($resql);
|
|
|
- if ($num > 0)
|
|
|
+
|
|
|
+ print load_fiche_titre($langs->trans("DiscountStillRemaining"));
|
|
|
+
|
|
|
+ if($isCustomer) {
|
|
|
+ if($isSupplier) {
|
|
|
+ print '<div class="fichecenter">';
|
|
|
+ print '<div class="fichehalfleft">';
|
|
|
+ print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
|
|
|
+ }
|
|
|
+
|
|
|
+ $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
|
|
|
+ $sql.= " rc.datec as dc, rc.description,";
|
|
|
+ $sql.= " rc.fk_facture_source,";
|
|
|
+ $sql.= " u.login, u.rowid as user_id,";
|
|
|
+ $sql.= " fa.facnumber as ref, fa.type as type";
|
|
|
+ $sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."societe_remise_except as rc";
|
|
|
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
|
|
|
+ $sql.= " WHERE rc.fk_soc = " . $object->id;
|
|
|
+ $sql.= " AND rc.entity = " . $conf->entity;
|
|
|
+ $sql.= " AND u.rowid = rc.fk_user";
|
|
|
+ $sql.= " AND rc.discount_type = 0"; // Eliminate supplier discounts
|
|
|
+ $sql.= " AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL)";
|
|
|
+ $sql.= " ORDER BY rc.datec DESC";
|
|
|
+
|
|
|
+ $resql=$db->query($sql);
|
|
|
+ if ($resql)
|
|
|
{
|
|
|
- while ($i < $num)
|
|
|
- {
|
|
|
- $obj = $db->fetch_object($resql);
|
|
|
-
|
|
|
- print '<tr class="oddeven">';
|
|
|
- print '<td>'.dol_print_date($db->jdate($obj->dc),'dayhour').'</td>';
|
|
|
- if (preg_match('/\(CREDIT_NOTE\)/',$obj->description))
|
|
|
- {
|
|
|
- print '<td class="nowrap">';
|
|
|
- $facturestatic->id=$obj->fk_facture_source;
|
|
|
- $facturestatic->ref=$obj->ref;
|
|
|
- $facturestatic->type=$obj->type;
|
|
|
- print preg_replace('/\(CREDIT_NOTE\)/',$langs->trans("CreditNote"),$obj->description).' '.$facturestatic->getNomURl(1);
|
|
|
- print '</td>';
|
|
|
- }
|
|
|
- elseif (preg_match('/\(DEPOSIT\)/',$obj->description))
|
|
|
- {
|
|
|
- print '<td class="nowrap">';
|
|
|
- $facturestatic->id=$obj->fk_facture_source;
|
|
|
- $facturestatic->ref=$obj->ref;
|
|
|
- $facturestatic->type=$obj->type;
|
|
|
- print preg_replace('/\(DEPOSIT\)/',$langs->trans("InvoiceDeposit"),$obj->description).' '.$facturestatic->getNomURl(1);
|
|
|
- print '</td>';
|
|
|
- }
|
|
|
- elseif (preg_match('/\(EXCESS RECEIVED\)/',$obj->description))
|
|
|
- {
|
|
|
- print '<td class="nowrap">';
|
|
|
- $facturestatic->id=$obj->fk_facture_source;
|
|
|
- $facturestatic->ref=$obj->ref;
|
|
|
- $facturestatic->type=$obj->type;
|
|
|
- print preg_replace('/\(EXCESS RECEIVED\)/',$langs->trans("ExcessReceived"),$obj->description).' '.$facturestatic->getNomURl(1);
|
|
|
- print '</td>';
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- print '<td>';
|
|
|
- print $obj->description;
|
|
|
- print '</td>';
|
|
|
- }
|
|
|
- print '<td class="nowrap">'.$langs->trans("NotConsumed").'</td>';
|
|
|
- print '<td align="right">'.price($obj->amount_ht).'</td>';
|
|
|
- print '<td align="right">'.price2num($obj->tva_tx,'MU').'%</td>';
|
|
|
- print '<td align="right">'.price($obj->amount_ttc).'</td>';
|
|
|
- print '<td align="center">';
|
|
|
- print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a>';
|
|
|
- print '</td>';
|
|
|
- if ($user->rights->societe->creer || $user->rights->facture->creer)
|
|
|
- {
|
|
|
- print '<td class="nowrap">';
|
|
|
- print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=split&remid='.$obj->rowid.($backtopage?'&backtopage='.urlencode($backtopage):'').'">'.img_split($langs->trans("SplitDiscount")).'</a>';
|
|
|
- print ' ';
|
|
|
- print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=remove&remid='.$obj->rowid.($backtopage?'&backtopage='.urlencode($backtopage):'').'">'.img_delete($langs->trans("RemoveDiscount")).'</a>';
|
|
|
- print '</td>';
|
|
|
- }
|
|
|
- else print '<td> </td>';
|
|
|
- print '</tr>';
|
|
|
-
|
|
|
- if ($_GET["action"]=='split' && GETPOST('remid') == $obj->rowid)
|
|
|
- {
|
|
|
- $showconfirminfo['rowid']=$obj->rowid;
|
|
|
- $showconfirminfo['amount_ttc']=$obj->amount_ttc;
|
|
|
- }
|
|
|
- $i++;
|
|
|
- }
|
|
|
+ print '<table width="100%" class="noborder">';
|
|
|
+ print '<tr class="liste_titre">';
|
|
|
+ print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
|
|
|
+ print '<td>'.$langs->trans("ReasonDiscount").'</td>';
|
|
|
+ print '<td width="150" class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
|
|
|
+ print '<td width="120" align="right">'.$langs->trans("AmountHT").'</td>';
|
|
|
+ print '<td width="80" align="right">'.$langs->trans("VATRate").'</td>';
|
|
|
+ print '<td width="120" align="right">'.$langs->trans("AmountTTC").'</td>';
|
|
|
+ print '<td width="100" align="center">'.$langs->trans("DiscountOfferedBy").'</td>';
|
|
|
+ print '<td width="50"> </td>';
|
|
|
+ print '</tr>';
|
|
|
+
|
|
|
+ $showconfirminfo=array();
|
|
|
+
|
|
|
+ $i = 0;
|
|
|
+ $num = $db->num_rows($resql);
|
|
|
+ if ($num > 0)
|
|
|
+ {
|
|
|
+ while ($i < $num)
|
|
|
+ {
|
|
|
+ $obj = $db->fetch_object($resql);
|
|
|
+
|
|
|
+ print '<tr class="oddeven">';
|
|
|
+ print '<td>'.dol_print_date($db->jdate($obj->dc),'dayhour').'</td>';
|
|
|
+ if (preg_match('/\(CREDIT_NOTE\)/',$obj->description))
|
|
|
+ {
|
|
|
+ print '<td class="nowrap">';
|
|
|
+ $facturestatic->id=$obj->fk_facture_source;
|
|
|
+ $facturestatic->ref=$obj->ref;
|
|
|
+ $facturestatic->type=$obj->type;
|
|
|
+ print preg_replace('/\(CREDIT_NOTE\)/',$langs->trans("CreditNote"),$obj->description).' '.$facturestatic->getNomURl(1);
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ elseif (preg_match('/\(DEPOSIT\)/',$obj->description))
|
|
|
+ {
|
|
|
+ print '<td class="nowrap">';
|
|
|
+ $facturestatic->id=$obj->fk_facture_source;
|
|
|
+ $facturestatic->ref=$obj->ref;
|
|
|
+ $facturestatic->type=$obj->type;
|
|
|
+ print preg_replace('/\(DEPOSIT\)/',$langs->trans("InvoiceDeposit"),$obj->description).' '.$facturestatic->getNomURl(1);
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ elseif (preg_match('/\(EXCESS RECEIVED\)/',$obj->description))
|
|
|
+ {
|
|
|
+ print '<td class="nowrap">';
|
|
|
+ $facturestatic->id=$obj->fk_facture_source;
|
|
|
+ $facturestatic->ref=$obj->ref;
|
|
|
+ $facturestatic->type=$obj->type;
|
|
|
+ print preg_replace('/\(EXCESS RECEIVED\)/',$langs->trans("ExcessReceived"),$obj->description).' '.$facturestatic->getNomURl(1);
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ print '<td>';
|
|
|
+ print $obj->description;
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ print '<td class="nowrap">'.$langs->trans("NotConsumed").'</td>';
|
|
|
+ print '<td align="right">'.price($obj->amount_ht).'</td>';
|
|
|
+ print '<td align="right">'.price2num($obj->tva_tx,'MU').'%</td>';
|
|
|
+ print '<td align="right">'.price($obj->amount_ttc).'</td>';
|
|
|
+ print '<td align="center">';
|
|
|
+ print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a>';
|
|
|
+ print '</td>';
|
|
|
+ if ($user->rights->societe->creer || $user->rights->facture->creer)
|
|
|
+ {
|
|
|
+ print '<td class="nowrap">';
|
|
|
+ print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=split&remid='.$obj->rowid.($backtopage?'&backtopage='.urlencode($backtopage):'').'">'.img_split($langs->trans("SplitDiscount")).'</a>';
|
|
|
+ print ' ';
|
|
|
+ print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=remove&remid='.$obj->rowid.($backtopage?'&backtopage='.urlencode($backtopage):'').'">'.img_delete($langs->trans("RemoveDiscount")).'</a>';
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ else print '<td> </td>';
|
|
|
+ print '</tr>';
|
|
|
+
|
|
|
+ if ($_GET["action"]=='split' && GETPOST('remid') == $obj->rowid)
|
|
|
+ {
|
|
|
+ $showconfirminfo['rowid']=$obj->rowid;
|
|
|
+ $showconfirminfo['amount_ttc']=$obj->amount_ttc;
|
|
|
+ }
|
|
|
+ $i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
|
|
|
+ }
|
|
|
+ $db->free($resql);
|
|
|
+ print "</table>";
|
|
|
+
|
|
|
+ if (count($showconfirminfo))
|
|
|
+ {
|
|
|
+ $amount1=price2num($showconfirminfo['amount_ttc']/2,'MT');
|
|
|
+ $amount2=($showconfirminfo['amount_ttc']-$amount1);
|
|
|
+ $formquestion=array(
|
|
|
+ 'text' => $langs->trans('TypeAmountOfEachNewDiscount'),
|
|
|
+ array('type' => 'text', 'name' => 'amount_ttc_1', 'label' => $langs->trans("AmountTTC").' 1', 'value' => $amount1, 'size' => '5'),
|
|
|
+ array('type' => 'text', 'name' => 'amount_ttc_2', 'label' => $langs->trans("AmountTTC").' 2', 'value' => $amount2, 'size' => '5')
|
|
|
+ );
|
|
|
+ $langs->load("dict");
|
|
|
+ print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&remid='.$showconfirminfo['rowid'].($backtopage?'&backtopage='.urlencode($backtopage):''), $langs->trans('SplitDiscount'), $langs->trans('ConfirmSplitDiscount',price($showconfirminfo['amount_ttc']),$langs->transnoentities("Currency".$conf->currency)), 'confirm_split', $formquestion, 0, 0);
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
|
|
|
+ dol_print_error($db);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if($isSupplier) {
|
|
|
+ if($isCustomer) {
|
|
|
+ print '</div>'; // class="fichehalfleft"
|
|
|
+ print '<div class="fichehalfright">';
|
|
|
+ print '<div class="ficheaddleft">';
|
|
|
+ print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
|
|
|
}
|
|
|
- $db->free($resql);
|
|
|
- print "</table>";
|
|
|
|
|
|
- if (count($showconfirminfo))
|
|
|
+ /*
|
|
|
+ * Liste remises fixes fournisseur restant en cours (= liees a aucune facture ni ligne de facture)
|
|
|
+ */
|
|
|
+ $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
|
|
|
+ $sql.= " rc.datec as dc, rc.description,";
|
|
|
+ $sql.= " rc.fk_invoice_supplier_source,";
|
|
|
+ $sql.= " u.login, u.rowid as user_id,";
|
|
|
+ $sql.= " fa.ref, fa.type as type";
|
|
|
+ $sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."societe_remise_except as rc";
|
|
|
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
|
|
|
+ $sql.= " WHERE rc.fk_soc = " . $object->id;
|
|
|
+ $sql.= " AND rc.entity = " . $conf->entity;
|
|
|
+ $sql.= " AND u.rowid = rc.fk_user";
|
|
|
+ $sql.= " AND rc.discount_type = 1"; // Eliminate customer discounts
|
|
|
+ $sql.= " AND (rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_line IS NULL)";
|
|
|
+ $sql.= " ORDER BY rc.datec DESC";
|
|
|
+
|
|
|
+ $resql=$db->query($sql);
|
|
|
+ if ($resql)
|
|
|
{
|
|
|
- $amount1=price2num($showconfirminfo['amount_ttc']/2,'MT');
|
|
|
- $amount2=($showconfirminfo['amount_ttc']-$amount1);
|
|
|
- $formquestion=array(
|
|
|
- 'text' => $langs->trans('TypeAmountOfEachNewDiscount'),
|
|
|
- array('type' => 'text', 'name' => 'amount_ttc_1', 'label' => $langs->trans("AmountTTC").' 1', 'value' => $amount1, 'size' => '5'),
|
|
|
- array('type' => 'text', 'name' => 'amount_ttc_2', 'label' => $langs->trans("AmountTTC").' 2', 'value' => $amount2, 'size' => '5')
|
|
|
- );
|
|
|
- $langs->load("dict");
|
|
|
- print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&remid='.$showconfirminfo['rowid'].($backtopage?'&backtopage='.urlencode($backtopage):''), $langs->trans('SplitDiscount'), $langs->trans('ConfirmSplitDiscount',price($showconfirminfo['amount_ttc']),$langs->transnoentities("Currency".$conf->currency)), 'confirm_split', $formquestion, 0, 0);
|
|
|
+ print '<table width="100%" class="noborder">';
|
|
|
+ print '<tr class="liste_titre">';
|
|
|
+ print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
|
|
|
+ print '<td>'.$langs->trans("ReasonDiscount").'</td>';
|
|
|
+ print '<td width="150" class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
|
|
|
+ print '<td width="120" align="right">'.$langs->trans("AmountHT").'</td>';
|
|
|
+ print '<td width="80" align="right">'.$langs->trans("VATRate").'</td>';
|
|
|
+ print '<td width="120" align="right">'.$langs->trans("AmountTTC").'</td>';
|
|
|
+ print '<td width="100" align="center">'.$langs->trans("DiscountOfferedBy").'</td>';
|
|
|
+ print '<td width="50"> </td>';
|
|
|
+ print '</tr>';
|
|
|
+
|
|
|
+ $showconfirminfo=array();
|
|
|
+
|
|
|
+ $i = 0;
|
|
|
+ $num = $db->num_rows($resql);
|
|
|
+ if ($num > 0)
|
|
|
+ {
|
|
|
+ while ($i < $num)
|
|
|
+ {
|
|
|
+ $obj = $db->fetch_object($resql);
|
|
|
+
|
|
|
+ print '<tr class="oddeven">';
|
|
|
+ print '<td>'.dol_print_date($db->jdate($obj->dc),'dayhour').'</td>';
|
|
|
+ if (preg_match('/\(CREDIT_NOTE\)/',$obj->description))
|
|
|
+ {
|
|
|
+ print '<td class="nowrap">';
|
|
|
+ $facturefournstatic->id=$obj->fk_invoice_supplier_source;
|
|
|
+ $facturefournstatic->ref=$obj->ref;
|
|
|
+ $facturefournstatic->type=$obj->type;
|
|
|
+ print preg_replace('/\(CREDIT_NOTE\)/',$langs->trans("CreditNote"),$obj->description).' '.$facturefournstatic->getNomURl(1);
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ elseif (preg_match('/\(DEPOSIT\)/',$obj->description))
|
|
|
+ {
|
|
|
+ print '<td class="nowrap">';
|
|
|
+ $facturefournstatic->id=$obj->fk_invoice_supplier_source;
|
|
|
+ $facturefournstatic->ref=$obj->ref;
|
|
|
+ $facturefournstatic->type=$obj->type;
|
|
|
+ print preg_replace('/\(DEPOSIT\)/',$langs->trans("InvoiceDeposit"),$obj->description).' '.$facturefournstatic->getNomURl(1);
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ elseif (preg_match('/\(EXCESS PAID\)/',$obj->description))
|
|
|
+ {
|
|
|
+ print '<td class="nowrap">';
|
|
|
+ $facturefournstatic->id=$obj->fk_invoice_supplier_source;
|
|
|
+ $facturefournstatic->ref=$obj->ref;
|
|
|
+ $facturefournstatic->type=$obj->type;
|
|
|
+ print preg_replace('/\(EXCESS PAID\)/',$langs->trans("ExcessPaid"),$obj->description).' '.$facturefournstatic->getNomURl(1);
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ print '<td>';
|
|
|
+ print $obj->description;
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ print '<td class="nowrap">'.$langs->trans("NotConsumed").'</td>';
|
|
|
+ print '<td align="right">'.price($obj->amount_ht).'</td>';
|
|
|
+ print '<td align="right">'.price2num($obj->tva_tx,'MU').'%</td>';
|
|
|
+ print '<td align="right">'.price($obj->amount_ttc).'</td>';
|
|
|
+ print '<td align="center">';
|
|
|
+ print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a>';
|
|
|
+ print '</td>';
|
|
|
+ if ($user->rights->societe->creer || $user->rights->facture->creer)
|
|
|
+ {
|
|
|
+ print '<td class="nowrap">';
|
|
|
+ print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=split&remid='.$obj->rowid.($backtopage?'&backtopage='.urlencode($backtopage):'').'">'.img_split($langs->trans("SplitDiscount")).'</a>';
|
|
|
+ print ' ';
|
|
|
+ print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=remove&remid='.$obj->rowid.($backtopage?'&backtopage='.urlencode($backtopage):'').'">'.img_delete($langs->trans("RemoveDiscount")).'</a>';
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ else print '<td> </td>';
|
|
|
+ print '</tr>';
|
|
|
+
|
|
|
+ if ($_GET["action"]=='split' && GETPOST('remid') == $obj->rowid)
|
|
|
+ {
|
|
|
+ $showconfirminfo['rowid']=$obj->rowid;
|
|
|
+ $showconfirminfo['amount_ttc']=$obj->amount_ttc;
|
|
|
+ }
|
|
|
+ $i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
|
|
|
+ }
|
|
|
+ $db->free($resql);
|
|
|
+ print "</table>";
|
|
|
+
|
|
|
+ if (count($showconfirminfo))
|
|
|
+ {
|
|
|
+ $amount1=price2num($showconfirminfo['amount_ttc']/2,'MT');
|
|
|
+ $amount2=($showconfirminfo['amount_ttc']-$amount1);
|
|
|
+ $formquestion=array(
|
|
|
+ 'text' => $langs->trans('TypeAmountOfEachNewDiscount'),
|
|
|
+ array('type' => 'text', 'name' => 'amount_ttc_1', 'label' => $langs->trans("AmountTTC").' 1', 'value' => $amount1, 'size' => '5'),
|
|
|
+ array('type' => 'text', 'name' => 'amount_ttc_2', 'label' => $langs->trans("AmountTTC").' 2', 'value' => $amount2, 'size' => '5')
|
|
|
+ );
|
|
|
+ $langs->load("dict");
|
|
|
+ print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&remid='.$showconfirminfo['rowid'].($backtopage?'&backtopage='.urlencode($backtopage):''), $langs->trans('SplitDiscount'), $langs->trans('ConfirmSplitDiscount',price($showconfirminfo['amount_ttc']),$langs->transnoentities("Currency".$conf->currency)), 'confirm_split', $formquestion, 0, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dol_print_error($db);
|
|
|
+ }
|
|
|
+
|
|
|
+ if($isCustomer) {
|
|
|
+ print '</div>'; // class="ficheaddleft"
|
|
|
+ print '</div>'; // class="fichehalfright"
|
|
|
+ print '</div>'; // class="fichecenter"
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- dol_print_error($db);
|
|
|
}
|
|
|
|
|
|
print '<br>';
|
|
@@ -454,150 +686,317 @@ if ($socid > 0)
|
|
|
/*
|
|
|
* List discount consumed (=liees a une ligne de facture ou facture)
|
|
|
*/
|
|
|
+
|
|
|
+ print load_fiche_titre($langs->trans("DiscountAlreadyCounted"));
|
|
|
+
|
|
|
+ if($isCustomer) {
|
|
|
+ if($isSupplier) {
|
|
|
+ print '<div class="fichecenter">';
|
|
|
+ print '<div class="fichehalfleft">';
|
|
|
+ print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
|
|
|
+ }
|
|
|
|
|
|
- // Remises liees a lignes de factures
|
|
|
- $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
|
|
|
- $sql.= " rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture,";
|
|
|
- $sql.= " rc.fk_facture_source,";
|
|
|
- $sql.= " u.login, u.rowid as user_id,";
|
|
|
- $sql.= " f.rowid, f.facnumber,";
|
|
|
- $sql.= " fa.facnumber as ref, fa.type as type";
|
|
|
- $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
|
|
|
- $sql.= " , ".MAIN_DB_PREFIX."user as u";
|
|
|
- $sql.= " , ".MAIN_DB_PREFIX."facturedet as fc";
|
|
|
- $sql.= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
|
|
|
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
|
|
|
- $sql.= " WHERE rc.fk_soc =". $object->id;
|
|
|
- $sql.= " AND rc.fk_facture_line = fc.rowid";
|
|
|
- $sql.= " AND fc.fk_facture = f.rowid";
|
|
|
- $sql.= " AND rc.fk_user = u.rowid";
|
|
|
- $sql.= " ORDER BY dc DESC";
|
|
|
- //$sql.= " UNION ";
|
|
|
- // Remises liees a factures
|
|
|
- $sql2 = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
|
|
|
- $sql2.= " rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture,";
|
|
|
- $sql2.= " rc.fk_facture_source,";
|
|
|
- $sql2.= " u.login, u.rowid as user_id,";
|
|
|
- $sql2.= " f.rowid, f.facnumber,";
|
|
|
- $sql2.= " fa.facnumber as ref, fa.type as type";
|
|
|
- $sql2.= " FROM ".MAIN_DB_PREFIX."facture as f";
|
|
|
- $sql2.= " , ".MAIN_DB_PREFIX."user as u";
|
|
|
- $sql2.= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
|
|
|
- $sql2.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
|
|
|
- $sql2.= " WHERE rc.fk_soc =". $object->id;
|
|
|
- $sql2.= " AND rc.fk_facture = f.rowid";
|
|
|
- $sql2.= " AND rc.fk_user = u.rowid";
|
|
|
-
|
|
|
- $sql2.= " ORDER BY dc DESC";
|
|
|
-
|
|
|
- $resql=$db->query($sql);
|
|
|
- $resql2=null;
|
|
|
- if ($resql) $resql2=$db->query($sql2);
|
|
|
- if ($resql2)
|
|
|
- {
|
|
|
- print load_fiche_titre($langs->trans("DiscountAlreadyCounted"));
|
|
|
- print '<table class="noborder" width="100%">';
|
|
|
- print '<tr class="liste_titre">';
|
|
|
- print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
|
|
|
- print '<td>'.$langs->trans("ReasonDiscount").'</td>';
|
|
|
- print '<td width="150" class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
|
|
|
- print '<td width="120" align="right">'.$langs->trans("AmountHT").'</td>';
|
|
|
- print '<td width="80" align="right">'.$langs->trans("VATRate").'</td>';
|
|
|
- print '<td width="120" align="right">'.$langs->trans("AmountTTC").'</td>';
|
|
|
- print '<td width="100" align="center">'.$langs->trans("Author").'</td>';
|
|
|
- print '<td width="50"> </td>';
|
|
|
- print '</tr>';
|
|
|
-
|
|
|
- $tab_sqlobj=array();
|
|
|
- $tab_sqlobjOrder=array();
|
|
|
- $num = $db->num_rows($resql);
|
|
|
- if ($num > 0)
|
|
|
+ // Remises liees a lignes de factures
|
|
|
+ $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
|
|
|
+ $sql.= " rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture,";
|
|
|
+ $sql.= " rc.fk_facture_source,";
|
|
|
+ $sql.= " u.login, u.rowid as user_id,";
|
|
|
+ $sql.= " f.rowid, f.facnumber,";
|
|
|
+ $sql.= " fa.facnumber as ref, fa.type as type";
|
|
|
+ $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
|
|
|
+ $sql.= " , ".MAIN_DB_PREFIX."user as u";
|
|
|
+ $sql.= " , ".MAIN_DB_PREFIX."facturedet as fc";
|
|
|
+ $sql.= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
|
|
|
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
|
|
|
+ $sql.= " WHERE rc.fk_soc =". $object->id;
|
|
|
+ $sql.= " AND rc.fk_facture_line = fc.rowid";
|
|
|
+ $sql.= " AND fc.fk_facture = f.rowid";
|
|
|
+ $sql.= " AND rc.fk_user = u.rowid";
|
|
|
+ $sql.= " AND rc.discount_type = 0"; // Eliminate supplier discounts
|
|
|
+ $sql.= " ORDER BY dc DESC";
|
|
|
+ //$sql.= " UNION ";
|
|
|
+ // Remises liees a factures
|
|
|
+ $sql2 = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
|
|
|
+ $sql2.= " rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture,";
|
|
|
+ $sql2.= " rc.fk_facture_source,";
|
|
|
+ $sql2.= " u.login, u.rowid as user_id,";
|
|
|
+ $sql2.= " f.rowid, f.facnumber,";
|
|
|
+ $sql2.= " fa.facnumber as ref, fa.type as type";
|
|
|
+ $sql2.= " FROM ".MAIN_DB_PREFIX."facture as f";
|
|
|
+ $sql2.= " , ".MAIN_DB_PREFIX."user as u";
|
|
|
+ $sql2.= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
|
|
|
+ $sql2.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
|
|
|
+ $sql2.= " WHERE rc.fk_soc =". $object->id;
|
|
|
+ $sql2.= " AND rc.fk_facture = f.rowid";
|
|
|
+ $sql2.= " AND rc.fk_user = u.rowid";
|
|
|
+ $sql2.= " AND rc.discount_type = 0"; // Eliminate supplier discounts
|
|
|
+ $sql2.= " ORDER BY dc DESC";
|
|
|
+
|
|
|
+ $resql=$db->query($sql);
|
|
|
+ $resql2=null;
|
|
|
+ if ($resql) $resql2=$db->query($sql2);
|
|
|
+ if ($resql2)
|
|
|
{
|
|
|
- for ($i = 0;$i < $num; $i++)
|
|
|
- {
|
|
|
- $sqlobj = $db->fetch_object($resql);
|
|
|
- $tab_sqlobj[] = $sqlobj;
|
|
|
- $tab_sqlobjOrder[]=$db->jdate($sqlobj->dc);
|
|
|
- }
|
|
|
+ print '<table class="noborder" width="100%">';
|
|
|
+ print '<tr class="liste_titre">';
|
|
|
+ print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
|
|
|
+ print '<td>'.$langs->trans("ReasonDiscount").'</td>';
|
|
|
+ print '<td width="150" class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
|
|
|
+ print '<td width="120" align="right">'.$langs->trans("AmountHT").'</td>';
|
|
|
+ print '<td width="80" align="right">'.$langs->trans("VATRate").'</td>';
|
|
|
+ print '<td width="120" align="right">'.$langs->trans("AmountTTC").'</td>';
|
|
|
+ print '<td width="100" align="center">'.$langs->trans("Author").'</td>';
|
|
|
+ print '<td width="50"> </td>';
|
|
|
+ print '</tr>';
|
|
|
+
|
|
|
+ $tab_sqlobj=array();
|
|
|
+ $tab_sqlobjOrder=array();
|
|
|
+ $num = $db->num_rows($resql);
|
|
|
+ if ($num > 0)
|
|
|
+ {
|
|
|
+ for ($i = 0;$i < $num; $i++)
|
|
|
+ {
|
|
|
+ $sqlobj = $db->fetch_object($resql);
|
|
|
+ $tab_sqlobj[] = $sqlobj;
|
|
|
+ $tab_sqlobjOrder[]=$db->jdate($sqlobj->dc);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $db->free($resql);
|
|
|
+
|
|
|
+ $num = $db->num_rows($resql2);
|
|
|
+ for ($i = 0;$i < $num;$i++)
|
|
|
+ {
|
|
|
+ $sqlobj = $db->fetch_object($resql2);
|
|
|
+ $tab_sqlobj[] = $sqlobj;
|
|
|
+ $tab_sqlobjOrder[]= $db->jdate($sqlobj->dc);
|
|
|
+ }
|
|
|
+ $db->free($resql2);
|
|
|
+ array_multisort($tab_sqlobjOrder,SORT_DESC,$tab_sqlobj);
|
|
|
+
|
|
|
+ $num = count($tab_sqlobj);
|
|
|
+ if ($num > 0)
|
|
|
+ {
|
|
|
+ $i = 0 ;
|
|
|
+ while ($i < $num )
|
|
|
+ {
|
|
|
+ $obj = array_shift($tab_sqlobj);
|
|
|
+ print '<tr class="oddeven">';
|
|
|
+ print '<td>'.dol_print_date($db->jdate($obj->dc),'dayhour').'</td>';
|
|
|
+ if (preg_match('/\(CREDIT_NOTE\)/',$obj->description))
|
|
|
+ {
|
|
|
+ print '<td class="nowrap">';
|
|
|
+ $facturestatic->id=$obj->fk_facture_source;
|
|
|
+ $facturestatic->ref=$obj->ref;
|
|
|
+ $facturestatic->type=$obj->type;
|
|
|
+ print preg_replace('/\(CREDIT_NOTE\)/',$langs->trans("CreditNote"),$obj->description).' '.$facturestatic->getNomURl(1);
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ elseif (preg_match('/\(DEPOSIT\)/',$obj->description))
|
|
|
+ {
|
|
|
+ print '<td class="nowrap">';
|
|
|
+ $facturestatic->id=$obj->fk_facture_source;
|
|
|
+ $facturestatic->ref=$obj->ref;
|
|
|
+ $facturestatic->type=$obj->type;
|
|
|
+ print preg_replace('/\(DEPOSIT\)/',$langs->trans("InvoiceDeposit"),$obj->description).' '.$facturestatic->getNomURl(1);
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ elseif (preg_match('/\(EXCESS RECEIVED\)/',$obj->description))
|
|
|
+ {
|
|
|
+ print '<td class="nowrap">';
|
|
|
+ $facturestatic->id=$obj->fk_facture_source;
|
|
|
+ $facturestatic->ref=$obj->ref;
|
|
|
+ $facturestatic->type=$obj->type;
|
|
|
+ print preg_replace('/\(EXCESS RECEIVED\)/',$langs->trans("Invoice"),$obj->description).' '.$facturestatic->getNomURl(1);
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ print '<td>';
|
|
|
+ print $obj->description;
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ print '<td align="left" class="nowrap"><a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->rowid.'">'.img_object($langs->trans("ShowBill"),'bill').' '.$obj->facnumber.'</a></td>';
|
|
|
+ print '<td align="right">'.price($obj->amount_ht).'</td>';
|
|
|
+ print '<td align="right">'.price2num($obj->tva_tx,'MU').'%</td>';
|
|
|
+ print '<td align="right">'.price($obj->amount_ttc).'</td>';
|
|
|
+ print '<td align="center">';
|
|
|
+ print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a>';
|
|
|
+ print '</td>';
|
|
|
+ print '<td> </td>';
|
|
|
+ print '</tr>';
|
|
|
+ $i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
|
|
|
+ }
|
|
|
+
|
|
|
+ print "</table>";
|
|
|
}
|
|
|
- $db->free($resql);
|
|
|
-
|
|
|
- $num = $db->num_rows($resql2);
|
|
|
- for ($i = 0;$i < $num;$i++)
|
|
|
+ else
|
|
|
{
|
|
|
- $sqlobj = $db->fetch_object($resql2);
|
|
|
- $tab_sqlobj[] = $sqlobj;
|
|
|
- $tab_sqlobjOrder[]= $db->jdate($sqlobj->dc);
|
|
|
+ dol_print_error($db);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if($isSupplier) {
|
|
|
+ if($isCustomer) {
|
|
|
+ print '</div>'; // class="fichehalfleft"
|
|
|
+ print '<div class="fichehalfright">';
|
|
|
+ print '<div class="ficheaddleft">';
|
|
|
+ print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
|
|
|
}
|
|
|
- $db->free($resql2);
|
|
|
- array_multisort($tab_sqlobjOrder,SORT_DESC,$tab_sqlobj);
|
|
|
|
|
|
- $num = count($tab_sqlobj);
|
|
|
- if ($num > 0)
|
|
|
+ // Remises liees a lignes de factures
|
|
|
+ $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
|
|
|
+ $sql.= " rc.datec as dc, rc.description, rc.fk_invoice_supplier_line, rc.fk_invoice_supplier,";
|
|
|
+ $sql.= " rc.fk_invoice_supplier_source,";
|
|
|
+ $sql.= " u.login, u.rowid as user_id,";
|
|
|
+ $sql.= " f.rowid, f.ref as facnumber,";
|
|
|
+ $sql.= " fa.ref, fa.type as type";
|
|
|
+ $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
|
|
|
+ $sql.= " , ".MAIN_DB_PREFIX."user as u";
|
|
|
+ $sql.= " , ".MAIN_DB_PREFIX."facture_fourn_det as fc";
|
|
|
+ $sql.= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
|
|
|
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
|
|
|
+ $sql.= " WHERE rc.fk_soc =". $object->id;
|
|
|
+ $sql.= " AND rc.fk_invoice_supplier_line = fc.rowid";
|
|
|
+ $sql.= " AND fc.fk_facture_fourn = f.rowid";
|
|
|
+ $sql.= " AND rc.fk_user = u.rowid";
|
|
|
+ $sql.= " AND rc.discount_type = 1"; // Eliminate customer discounts
|
|
|
+ $sql.= " ORDER BY dc DESC";
|
|
|
+ //$sql.= " UNION ";
|
|
|
+ // Remises liees a factures
|
|
|
+ $sql2 = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
|
|
|
+ $sql2.= " rc.datec as dc, rc.description, rc.fk_invoice_supplier_line, rc.fk_invoice_supplier,";
|
|
|
+ $sql2.= " rc.fk_invoice_supplier_source,";
|
|
|
+ $sql2.= " u.login, u.rowid as user_id,";
|
|
|
+ $sql2.= " f.rowid, f.ref as facnumber,";
|
|
|
+ $sql2.= " fa.ref, fa.type as type";
|
|
|
+ $sql2.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
|
|
|
+ $sql2.= " , ".MAIN_DB_PREFIX."user as u";
|
|
|
+ $sql2.= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
|
|
|
+ $sql2.= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
|
|
|
+ $sql2.= " WHERE rc.fk_soc =". $object->id;
|
|
|
+ $sql2.= " AND rc.fk_invoice_supplier = f.rowid";
|
|
|
+ $sql2.= " AND rc.fk_user = u.rowid";
|
|
|
+ $sql2.= " AND rc.discount_type = 1"; // Eliminate customer discounts
|
|
|
+ $sql2.= " ORDER BY dc DESC";
|
|
|
+
|
|
|
+ $resql=$db->query($sql);
|
|
|
+ $resql2=null;
|
|
|
+ if ($resql) $resql2=$db->query($sql2);
|
|
|
+ if ($resql2)
|
|
|
{
|
|
|
- $i = 0 ;
|
|
|
- while ($i < $num )
|
|
|
- {
|
|
|
- $obj = array_shift($tab_sqlobj);
|
|
|
- print '<tr class="oddeven">';
|
|
|
- print '<td>'.dol_print_date($db->jdate($obj->dc),'dayhour').'</td>';
|
|
|
- if (preg_match('/\(CREDIT_NOTE\)/',$obj->description))
|
|
|
- {
|
|
|
- print '<td class="nowrap">';
|
|
|
- $facturestatic->id=$obj->fk_facture_source;
|
|
|
- $facturestatic->ref=$obj->ref;
|
|
|
- $facturestatic->type=$obj->type;
|
|
|
- print preg_replace('/\(CREDIT_NOTE\)/',$langs->trans("CreditNote"),$obj->description).' '.$facturestatic->getNomURl(1);
|
|
|
- print '</td>';
|
|
|
- }
|
|
|
- elseif (preg_match('/\(DEPOSIT\)/',$obj->description))
|
|
|
- {
|
|
|
- print '<td class="nowrap">';
|
|
|
- $facturestatic->id=$obj->fk_facture_source;
|
|
|
- $facturestatic->ref=$obj->ref;
|
|
|
- $facturestatic->type=$obj->type;
|
|
|
- print preg_replace('/\(DEPOSIT\)/',$langs->trans("InvoiceDeposit"),$obj->description).' '.$facturestatic->getNomURl(1);
|
|
|
- print '</td>';
|
|
|
- }
|
|
|
- elseif (preg_match('/\(EXCESS RECEIVED\)/',$obj->description))
|
|
|
- {
|
|
|
- print '<td class="nowrap">';
|
|
|
- $facturestatic->id=$obj->fk_facture_source;
|
|
|
- $facturestatic->ref=$obj->ref;
|
|
|
- $facturestatic->type=$obj->type;
|
|
|
- print preg_replace('/\(EXCESS RECEIVED\)/',$langs->trans("Invoice"),$obj->description).' '.$facturestatic->getNomURl(1);
|
|
|
- print '</td>';
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- print '<td>';
|
|
|
- print $obj->description;
|
|
|
- print '</td>';
|
|
|
- }
|
|
|
- print '<td align="left" class="nowrap"><a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->rowid.'">'.img_object($langs->trans("ShowBill"),'bill').' '.$obj->facnumber.'</a></td>';
|
|
|
- print '<td align="right">'.price($obj->amount_ht).'</td>';
|
|
|
- print '<td align="right">'.price2num($obj->tva_tx,'MU').'%</td>';
|
|
|
- print '<td align="right">'.price($obj->amount_ttc).'</td>';
|
|
|
- print '<td align="center">';
|
|
|
- print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a>';
|
|
|
- print '</td>';
|
|
|
- print '<td> </td>';
|
|
|
- print '</tr>';
|
|
|
- $i++;
|
|
|
- }
|
|
|
+ print '<table class="noborder" width="100%">';
|
|
|
+ print '<tr class="liste_titre">';
|
|
|
+ print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
|
|
|
+ print '<td>'.$langs->trans("ReasonDiscount").'</td>';
|
|
|
+ print '<td width="150" class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
|
|
|
+ print '<td width="120" align="right">'.$langs->trans("AmountHT").'</td>';
|
|
|
+ print '<td width="80" align="right">'.$langs->trans("VATRate").'</td>';
|
|
|
+ print '<td width="120" align="right">'.$langs->trans("AmountTTC").'</td>';
|
|
|
+ print '<td width="100" align="center">'.$langs->trans("Author").'</td>';
|
|
|
+ print '<td width="50"> </td>';
|
|
|
+ print '</tr>';
|
|
|
+
|
|
|
+ $tab_sqlobj=array();
|
|
|
+ $tab_sqlobjOrder=array();
|
|
|
+ $num = $db->num_rows($resql);
|
|
|
+ if ($num > 0)
|
|
|
+ {
|
|
|
+ for ($i = 0;$i < $num; $i++)
|
|
|
+ {
|
|
|
+ $sqlobj = $db->fetch_object($resql);
|
|
|
+ $tab_sqlobj[] = $sqlobj;
|
|
|
+ $tab_sqlobjOrder[]=$db->jdate($sqlobj->dc);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $db->free($resql);
|
|
|
+
|
|
|
+ $num = $db->num_rows($resql2);
|
|
|
+ for ($i = 0;$i < $num;$i++)
|
|
|
+ {
|
|
|
+ $sqlobj = $db->fetch_object($resql2);
|
|
|
+ $tab_sqlobj[] = $sqlobj;
|
|
|
+ $tab_sqlobjOrder[]= $db->jdate($sqlobj->dc);
|
|
|
+ }
|
|
|
+ $db->free($resql2);
|
|
|
+ array_multisort($tab_sqlobjOrder,SORT_DESC,$tab_sqlobj);
|
|
|
+
|
|
|
+ $num = count($tab_sqlobj);
|
|
|
+ if ($num > 0)
|
|
|
+ {
|
|
|
+ $i = 0 ;
|
|
|
+ while ($i < $num )
|
|
|
+ {
|
|
|
+ $obj = array_shift($tab_sqlobj);
|
|
|
+ print '<tr class="oddeven">';
|
|
|
+ print '<td>'.dol_print_date($db->jdate($obj->dc),'dayhour').'</td>';
|
|
|
+ if (preg_match('/\(CREDIT_NOTE\)/',$obj->description))
|
|
|
+ {
|
|
|
+ print '<td class="nowrap">';
|
|
|
+ $facturefournstatic->id=$obj->fk_invoice_supplier_source;
|
|
|
+ $facturefournstatic->ref=$obj->ref;
|
|
|
+ $facturefournstatic->type=$obj->type;
|
|
|
+ print preg_replace('/\(CREDIT_NOTE\)/',$langs->trans("CreditNote"),$obj->description).' '.$facturefournstatic->getNomURl(1);
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ elseif (preg_match('/\(DEPOSIT\)/',$obj->description))
|
|
|
+ {
|
|
|
+ print '<td class="nowrap">';
|
|
|
+ $facturefournstatic->id=$obj->fk_invoice_supplier_source;
|
|
|
+ $facturefournstatic->ref=$obj->ref;
|
|
|
+ $facturefournstatic->type=$obj->type;
|
|
|
+ print preg_replace('/\(DEPOSIT\)/',$langs->trans("InvoiceDeposit"),$obj->description).' '.$facturefournstatic->getNomURl(1);
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ elseif (preg_match('/\(EXCESS PAID\)/',$obj->description))
|
|
|
+ {
|
|
|
+ print '<td class="nowrap">';
|
|
|
+ $facturefournstatic->id=$obj->fk_invoice_supplier_source;
|
|
|
+ $facturefournstatic->ref=$obj->ref;
|
|
|
+ $facturefournstatic->type=$obj->type;
|
|
|
+ print preg_replace('/\(EXCESS PAID\)/',$langs->trans("Invoice"),$obj->description).' '.$facturefournstatic->getNomURl(1);
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ print '<td>';
|
|
|
+ print $obj->description;
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+ print '<td align="left" class="nowrap"><a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$obj->rowid.'">'.img_object($langs->trans("ShowBill"),'bill').' '.$obj->facnumber.'</a></td>';
|
|
|
+ print '<td align="right">'.price($obj->amount_ht).'</td>';
|
|
|
+ print '<td align="right">'.price2num($obj->tva_tx,'MU').'%</td>';
|
|
|
+ print '<td align="right">'.price($obj->amount_ttc).'</td>';
|
|
|
+ print '<td align="center">';
|
|
|
+ print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a>';
|
|
|
+ print '</td>';
|
|
|
+ print '<td> </td>';
|
|
|
+ print '</tr>';
|
|
|
+ $i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
|
|
|
+ }
|
|
|
+
|
|
|
+ print "</table>";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
|
|
|
+ dol_print_error($db);
|
|
|
}
|
|
|
|
|
|
- print "</table>";
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- dol_print_error($db);
|
|
|
+ if($isCustomer) {
|
|
|
+ print '</div>'; // class="ficheaddleft"
|
|
|
+ print '</div>'; // class="fichehalfright"
|
|
|
+ print '</div>'; // class="fichecenter"
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
llxFooter();
|