Skip to content

Commit

Permalink
Merge pull request #8276 from ATM-Consulting/develop_atm
Browse files Browse the repository at this point in the history
NEW: supplier credit notes & discounts (absolute and relative)
  • Loading branch information
eldy committed Mar 8, 2018
2 parents e0af4f8 + fad521d commit 1c9e714
Show file tree
Hide file tree
Showing 34 changed files with 2,030 additions and 732 deletions.
4 changes: 2 additions & 2 deletions htdocs/accountancy/journal/purchasesjournal.php
Expand Up @@ -882,7 +882,7 @@ function writebookkeeping() {
else print $accountoshow;
print '</td>';
print "<td>" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->ref_supplier . ' - ' . $langs->trans("SubledgerAccount") . "</td>";
print '<td align="right">' . ($mt < 0 ? - price(- $mt) : '') . "</td>";
print '<td align="right">'. ($mt < 0 ? price(- $mt) : '') . "</td>";
print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
print "</tr>";
//}
Expand Down Expand Up @@ -976,7 +976,7 @@ function writebookkeeping() {
print "<td>";
print '</td>';
print "<td>" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->ref_supplier . ' - ' . $langs->trans("VAT") . " NPR (counterpart)</td>";
print '<td align="right">' . ($mt < 0 ? - price(- $mt) : '') . "</td>";
print '<td align="right">' . ($mt < 0 ? price(- $mt) : '') . "</td>";
print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
print "</tr>";
}
Expand Down
55 changes: 23 additions & 32 deletions htdocs/comm/propal/card.php
Expand Up @@ -1458,17 +1458,13 @@

// Ligne info remises tiers
print '<tr><td>' . $langs->trans('Discounts') . '</td><td>';
if ($soc->remise_percent)
print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent);
else
print $langs->trans("CompanyHasNoRelativeDiscount");

$absolute_discount = $soc->getAvailableDiscounts();
print '. ';
if ($absolute_discount)
print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount, 0, $langs, 1, -1, -1, $conf->currency));
else
print $langs->trans("CompanyHasNoAbsoluteDiscount");
print '.';

$thirdparty = $soc;
$discount_type = 0;
$backtopage = urlencode($_SERVER["PHP_SELF"] . '?socid=' . $thirdparty->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid'));
include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
print '</td></tr>';
}

Expand Down Expand Up @@ -1875,31 +1871,26 @@
print '<table class="border" width="100%">';

// Link for thirdparty discounts
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
$filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
} else {
$filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
$filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
}

print '<tr><td class="titlefield">' . $langs->trans('Discounts') . '</td><td>';
if ($soc->remise_percent)
print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent);
else
print $langs->trans("CompanyHasNoRelativeDiscount");
print '. ';
$absolute_discount = $soc->getAvailableDiscounts('', 'fk_facture_source IS NULL');
$absolute_creditnote = $soc->getAvailableDiscounts('', 'fk_facture_source IS NOT NULL');

$absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount);
$absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote);
$absolute_discount = price2num($absolute_discount, 'MT');
$absolute_creditnote = price2num($absolute_creditnote, 'MT');
if ($absolute_discount) {
if ($object->statut > Propal::STATUS_DRAFT) {
print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount, 0, $langs, 0, 0, -1, $conf->currency));
} else {
// Remise dispo de type non avoir
$filter = 'fk_facture_source IS NULL';
print '<br>';
$form->form_remise_dispo($_SERVER["PHP_SELF"] . '?id=' . $object->id, 0, 'remise_id', $soc->id, $absolute_discount, $filter, 0, '', 1);
}
}
if ($absolute_creditnote) {
print $langs->trans("CompanyHasCreditNote", price($absolute_creditnote, 0, $langs, 0, 0, -1, $conf->currency)) . '. ';
}
if (! $absolute_discount && ! $absolute_creditnote)
print $langs->trans("CompanyHasNoAbsoluteDiscount") . '.';

$thirdparty = $soc;
$discount_type = 0;
$backtopage = urlencode($_SERVER["PHP_SELF"] . '?id=' . $object->id);
include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';

print '</td></tr>';

// Date of proposal
Expand Down
215 changes: 166 additions & 49 deletions htdocs/comm/remise.php
Expand Up @@ -56,7 +56,14 @@
{
$object = new Societe($db);
$object->fetch($id);
$result=$object->set_remise_client(price2num(GETPOST("remise")),GETPOST("note"),$user);

$discount_type = GETPOST('discount_type', 'int');

if(! empty($discount_type)) {
$result=$object->set_remise_supplier(price2num(GETPOST("remise")),GETPOST("note"),$user);
} else {
$result=$object->set_remise_client(price2num(GETPOST("remise")),GETPOST("note"),$user);
}

if ($result > 0)
{
Expand Down Expand Up @@ -100,7 +107,8 @@

$head = societe_prepare_head($object);


$isCustomer = $object->client == 1 || $object->client == 3;
$isSupplier = $object->fournisseur == 1;

print '<form method="POST" action="remise.php?id='.$object->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
Expand All @@ -114,20 +122,58 @@
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">';

// Discount
print '<tr><td class="titlefield">';
print $langs->trans("CustomerRelativeDiscount").'</td><td>'.price2num($object->remise_percent)."%</td></tr>";
if($isCustomer) {
// Customer discount
print '<tr><td class="titlefield">';
print $langs->trans("CustomerRelativeDiscount").'</td><td>'.price2num($object->remise_percent)."%</td></tr>";
}

if($isSupplier) {
// Supplier discount
print '<tr><td class="titlefield">';
print $langs->trans("SupplierRelativeDiscount").'</td><td>'.price2num($object->remise_supplier_percent)."%</td></tr>";
}

print '</table>';
print '<br>';

print load_fiche_titre($langs->trans("NewRelativeDiscount"),'','');

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 centpercent">';

if($isCustomer && $isSupplier) {
// Discount type
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>';
}

// New value
print '<tr><td class="titlefield fieldrequired">';
print $langs->trans("NewValue").'</td><td><input type="text" size="5" name="remise" value="'.dol_escape_htmltag(GETPOST("remise")).'">%</td></tr>';
Expand Down Expand Up @@ -155,57 +201,128 @@

print '<br>';

if($isCustomer) {
if($isSupplier) {
print '<div class="fichecenter">';
print '<div class="fichehalfleft">';
print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
}

/*
* List log of all percent discounts
*/
$sql = "SELECT rc.rowid, rc.remise_client as remise_percent, rc.note, rc.datec as dc,";
$sql.= " u.login, u.rowid as user_id";
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE rc.fk_soc = " . $object->id;
$sql.= " AND rc.entity = " . $conf->entity;
$sql.= " AND u.rowid = rc.fk_user_author";
$sql.= " ORDER BY rc.datec DESC";

$resql=$db->query($sql);
if ($resql)
{
print '<table class="noborder" width="100%">';
$tag = !$tag;
print '<tr class="liste_titre">';
print '<td width="160">'.$langs->trans("Date").'</td>';
print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
print '<td align="left">'.$langs->trans("NoteReason").'</td>';
print '<td align="center">'.$langs->trans("User").'</td>';
print '</tr>';
$num = $db->num_rows($resql);
if ($num > 0)
{
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object($resql);
print '<tr class="oddeven">';
print '<td>'.dol_print_date($db->jdate($obj->dc),"dayhour").'</td>';
print '<td align="center">'.price2num($obj->remise_percent).'%</td>';
print '<td align="left">'.$obj->note.'</td>';
print '<td align="center"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a></td>';
print '</tr>';
$i++;
}
/*
* List log of all customer percent discounts
*/
$sql = "SELECT rc.rowid, rc.remise_client as remise_percent, rc.note, rc.datec as dc,";
$sql.= " u.login, u.rowid as user_id";
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE rc.fk_soc = " . $object->id;
$sql.= " AND rc.entity = " . $conf->entity;
$sql.= " AND u.rowid = rc.fk_user_author";
$sql.= " ORDER BY rc.datec DESC";

$resql=$db->query($sql);
if ($resql)
{
print '<table class="noborder" width="100%">';
$tag = !$tag;
print '<tr class="liste_titre">';
print '<td width="160">'.$langs->trans("Date").'</td>';
print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
print '<td align="left">'.$langs->trans("NoteReason").'</td>';
print '<td align="center">'.$langs->trans("User").'</td>';
print '</tr>';
$num = $db->num_rows($resql);
if ($num > 0)
{
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object($resql);
print '<tr class="oddeven">';
print '<td>'.dol_print_date($db->jdate($obj->dc),"dayhour").'</td>';
print '<td align="center">'.price2num($obj->remise_percent).'%</td>';
print '<td align="left">'.$obj->note.'</td>';
print '<td align="center"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a></td>';
print '</tr>';
$i++;
}
}
else
{
print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
}
$db->free($resql);
print "</table>";
}
else
{
print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
dol_print_error($db);
}
$db->free($resql);
print "</table>";
}
else
{
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"), '', '');
}

/*
* List log of all supplier percent discounts
*/
$sql = "SELECT rc.rowid, rc.remise_supplier as remise_percent, rc.note, rc.datec as dc,";
$sql.= " u.login, u.rowid as user_id";
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_supplier as rc, ".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE rc.fk_soc = " . $object->id;
$sql.= " AND rc.entity = " . $conf->entity;
$sql.= " AND u.rowid = rc.fk_user_author";
$sql.= " ORDER BY rc.datec DESC";

$resql=$db->query($sql);
if ($resql)
{
print '<table class="noborder" width="100%">';
$tag = !$tag;
print '<tr class="liste_titre">';
print '<td width="160">'.$langs->trans("Date").'</td>';
print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
print '<td align="left">'.$langs->trans("NoteReason").'</td>';
print '<td align="center">'.$langs->trans("User").'</td>';
print '</tr>';
$num = $db->num_rows($resql);
if ($num > 0)
{
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object($resql);
print '<tr class="oddeven">';
print '<td>'.dol_print_date($db->jdate($obj->dc),"dayhour").'</td>';
print '<td align="center">'.price2num($obj->remise_percent).'%</td>';
print '<td align="left">'.$obj->note.'</td>';
print '<td align="center"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a></td>';
print '</tr>';
$i++;
}
}
else
{
print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
}
$db->free($resql);
print "</table>";
}
else
{
dol_print_error($db);
}

if($isCustomer) {
print '</div>'; // class="ficheaddleft"
print '</div>'; // class="fichehalfright"
print '</div>'; // class="fichecenter"
}
}
}

llxFooter();
Expand Down

0 comments on commit 1c9e714

Please sign in to comment.