| '.$langs->trans('Discounts');
+ print ' | ';
+ if ($soc->remise_percent) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_percent);
+ else print $langs->trans("CompanyHasNoRelativeDiscount");
+ //print ' ('.$addrelativediscount.')';
+
+ if ($absolute_discount > 0)
+ {
+ print '. ';
+ if ($object->statut > 0 || $object->type == 2 || $object->type == 3)
+ {
+ if ($object->statut == 0)
{
- $facturereplacement=new Facture($db);
- $facturereplacement->fetch($objectidnext);
- $statusreplacement=$facturereplacement->statut;
- }
- if ($objectidnext && $statusreplacement == 0)
- {
- print ' '.$langs->trans("ErrorCantCancelIfReplacementInvoiceNotValidated").' ';
+ print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
+ print '. ';
}
else
{
- // Code
- $close[1]['code']='badcustomer';
- $close[2]['code']='abandon';
- // Help
- $close[1]['label']=$langs->trans("ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
- $close[2]['label']=$langs->trans("ConfirmClassifyAbandonReasonOtherDesc");
- // Texte
- $close[1]['reason']=$form->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonBadCustomer",$object->ref),$close[1]['label'],1);
- $close[2]['reason']=$form->textwithpicto($langs->transnoentities("ConfirmClassifyAbandonReasonOther"),$close[2]['label'],1);
- // arrayreasons
- $arrayreasons[$close[1]['code']]=$close[1]['reason'];
- $arrayreasons[$close[2]['code']]=$close[2]['reason'];
-
- // Cree un tableau formulaire
- $formquestion=array(
- 'text' => $langs->trans("ConfirmCancelBillQuestion"),
- array('type' => 'radio', 'name' => 'close_code', 'label' => $langs->trans("Reason"), 'values' => $arrayreasons),
- array('type' => 'text', 'name' => 'close_note', 'label' => $langs->trans("Comment"), 'value' => '', 'size' => '100')
- );
-
- $formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$object->id,$langs->trans('CancelBill'),$langs->trans('ConfirmCancelBill',$object->ref),'confirm_canceled',$formquestion,"yes");
- }
- }
-
- // Confirmation de la suppression d'une ligne produit
- if ($action == 'ask_deleteline')
- {
- $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 'no', 1);
- }
-
- // Clone confirmation
- if ($action == 'clone')
- {
- // Create an array for form
- $formquestion=array(
- //'text' => $langs->trans("ConfirmClone"),
- //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1)
- );
- // Paiement incomplet. On demande si motif = escompte ou autre
- $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id,$langs->trans('CloneInvoice'),$langs->trans('ConfirmCloneInvoice',$object->ref),'confirm_clone',$formquestion,'yes',1);
- }
-
- if (! $formconfirm)
- {
- $parameters=array('lineid'=>$lineid);
- $formconfirm=$hookmanager->executeHooks('formConfirm',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
- }
-
- // Print form confirm
- print $formconfirm;
-
-
-
-
- // Invoice content
-
- print '';
-
- $linkback = ''.$langs->trans("BackToList").'';
-
- // Ref
- print '| '.$langs->trans('Ref').' | ';
- print '';
- $morehtmlref='';
- $discount=new DiscountAbsolute($db);
- $result=$discount->fetch(0,$object->id);
- if ($result > 0)
- {
- $morehtmlref=' ('.$langs->trans("CreditNoteConvertedIntoDiscount",$discount->getNomUrl(1,'discount')).')';
- }
- if ($result < 0)
- {
- dol_print_error('',$discount->error);
- }
- print $form->showrefnav($object, 'ref', $linkback, 1, 'facnumber', 'ref', $morehtmlref);
- print ' | ';
-
- // Ref customer
- print '| ';
- print '';
- print ' | ';
- print '';
- if ($user->rights->facture->creer && $action == 'refclient')
- {
- print '';
- }
- else
- {
- print $object->ref_client;
- }
- print ' | ';
-
- // Third party
- print '| ';
- print '';
- print ' | ';
- if ($action == 'editthirdparty')
- {
- $form->form_thirdparty($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->socid,'socid');
- }
- else
- {
- print ' '.$soc->getNomUrl(1,'compta');
- print ' ';
- print '('.$langs->trans('OtherBills').'';
- // Outstanding Bill
- $outstandigBills=$soc->get_OutstandingBill();
- print ' - '.$langs->trans('CurrentOutstandingBill').': ';
- print price($outstandigBills,'',$langs,0,0,-1,$conf->currency);
- if ($soc->outstanding_limit != '')
- {
- if ($outstandigBills > $soc->outstanding_limit) print img_warning($langs->trans("OutstandingBillReached"));
- print ' / '.price($soc->outstanding_limit);
- }
- print ')';
- }
- print ' | ';
-
- // Type
- print '| '.$langs->trans('Type').' | ';
- print $object->getLibType();
- if ($object->type == 1)
- {
- $facreplaced=new Facture($db);
- $facreplaced->fetch($object->fk_facture_source);
- print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')';
- }
- if ($object->type == 2)
- {
- $facusing=new Facture($db);
- $facusing->fetch($object->fk_facture_source);
- print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')';
- }
-
- $facidavoir=$object->getListIdAvoirFromInvoice();
- if (count($facidavoir) > 0)
- {
- print ' ('.$langs->transnoentities("InvoiceHasAvoir");
- $i=0;
- foreach($facidavoir as $id)
- {
- if ($i==0) print ' ';
- else print ',';
- $facavoir=new Facture($db);
- $facavoir->fetch($id);
- print $facavoir->getNomUrl(1);
- }
- print ')';
- }
- if ($objectidnext > 0)
- {
- $facthatreplace=new Facture($db);
- $facthatreplace->fetch($objectidnext);
- print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
- }
- print ' | ';
-
- // Relative and absolute discounts
- $addrelativediscount='id.'">'.$langs->trans("EditRelativeDiscounts").'';
- $addabsolutediscount='id.'">'.$langs->trans("EditGlobalDiscounts").'';
- $addcreditnote='id.'">'.$langs->trans("AddCreditNote").'';
-
- print '| '.$langs->trans('Discounts');
- print ' | ';
- if ($soc->remise_percent) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_percent);
- else print $langs->trans("CompanyHasNoRelativeDiscount");
- //print ' ('.$addrelativediscount.')';
-
- if ($absolute_discount > 0)
- {
- print '. ';
- if ($object->statut > 0 || $object->type == 2 || $object->type == 3)
- {
- if ($object->statut == 0)
+ if ($object->statut < 1 || $object->type == 2 || $object->type == 3)
{
- print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
- print '. ';
+ $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
+ print ' '.$text.'. ';
}
else
{
- if ($object->statut < 1 || $object->type == 2 || $object->type == 3)
- {
- $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
- print ' '.$text.'. ';
- }
- else
- {
- $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
- $text2=$langs->trans("AbsoluteDiscountUse");
- print $form->textwithpicto($text,$text2);
- }
+ $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
+ $text2=$langs->trans("AbsoluteDiscountUse");
+ print $form->textwithpicto($text,$text2);
}
}
- else
- {
- // Remise dispo de type remise fixe (not credit note)
- print ' ';
- $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, GETPOST('discountid'), 'remise_id', $soc->id, $absolute_discount, $filterabsolutediscount, $resteapayer, ' ('.$addabsolutediscount.')');
- }
}
else
{
- if ($absolute_creditnote > 0) // If not, link will be added later
- {
- if ($object->statut == 0 && $object->type != 2 && $object->type != 3) print ' ('.$addabsolutediscount.') ';
- else print '. ';
- }
- else print '. ';
+ // Remise dispo de type remise fixe (not credit note)
+ print ' ';
+ $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, GETPOST('discountid'), 'remise_id', $soc->id, $absolute_discount, $filterabsolutediscount, $resteapayer, ' ('.$addabsolutediscount.')');
}
- if ($absolute_creditnote > 0)
+ }
+ else
+ {
+ if ($absolute_creditnote > 0) // If not, link will be added later
{
- // If validated, we show link "add credit note to payment"
- if ($object->statut != 1 || $object->type == 2 || $object->type == 3)
- {
- if ($object->statut == 0 && $object->type != 3)
- {
- $text=$langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency));
- print $form->textwithpicto($text,$langs->trans("CreditNoteDepositUse"));
- }
- else
- {
- print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency)).'.';
- }
- }
- else
- {
- // Remise dispo de type avoir
- if (! $absolute_discount) print ' ';
- //$form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, $resteapayer);
- $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, 0); // We must allow credit not even if amount is higher
- }
- }
- if (! $absolute_discount && ! $absolute_creditnote)
- {
- print $langs->trans("CompanyHasNoAbsoluteDiscount");
if ($object->statut == 0 && $object->type != 2 && $object->type != 3) print ' ('.$addabsolutediscount.') ';
else print '. ';
}
- //if ($object->statut == 0 && $object->type != 2 && $object->type != 3)
- // {
- //if (! $absolute_discount && ! $absolute_creditnote) print ' ';
- //print ' - ';
- //print $addabsolutediscount;
- //print ' - '.$addcreditnote; // We disbale link to credit note
- //}
- print ' | ';
-
- // Date invoice
- print '';
- print '| ';
- print $langs->trans('Date');
- print ' | ';
- if ($object->type != 2 && $action != 'editinvoicedate' && ! empty($object->brouillon) && $user->rights->facture->creer) print 'id.'">'.img_edit($langs->trans('SetDate'),1).' | ';
- print ' ';
- print ' | ';
-
- if ($object->type != 2)
+ else print '. ';
+ }
+ if ($absolute_creditnote > 0)
+ {
+ // If validated, we show link "add credit note to payment"
+ if ($object->statut != 1 || $object->type == 2 || $object->type == 3)
{
- if ($action == 'editinvoicedate')
+ if ($object->statut == 0 && $object->type != 3)
{
- $form->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->date,'invoicedate');
+ $text=$langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency));
+ print $form->textwithpicto($text,$langs->trans("CreditNoteDepositUse"));
}
else
{
- print dol_print_date($object->date,'daytext');
+ print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency)).'.';
}
}
else
+ {
+ // Remise dispo de type avoir
+ if (! $absolute_discount) print ' ';
+ //$form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, $resteapayer);
+ $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, 0); // We must allow credit not even if amount is higher
+ }
+ }
+ if (! $absolute_discount && ! $absolute_creditnote)
+ {
+ print $langs->trans("CompanyHasNoAbsoluteDiscount");
+ if ($object->statut == 0 && $object->type != 2 && $object->type != 3) print ' ('.$addabsolutediscount.') ';
+ else print '. ';
+ }
+ //if ($object->statut == 0 && $object->type != 2 && $object->type != 3)
+ // {
+ //if (! $absolute_discount && ! $absolute_creditnote) print ' ';
+ //print ' - ';
+ //print $addabsolutediscount;
+ //print ' - '.$addcreditnote; // We disbale link to credit note
+ //}
+ print ' | ';
+
+ // Date invoice
+ print '';
+ print '| ';
+ print $langs->trans('Date');
+ print ' | ';
+ if ($object->type != 2 && $action != 'editinvoicedate' && ! empty($object->brouillon) && $user->rights->facture->creer) print 'id.'">'.img_edit($langs->trans('SetDate'),1).' | ';
+ print ' ';
+ print ' | ';
+
+ if ($object->type != 2)
+ {
+ if ($action == 'editinvoicedate')
+ {
+ $form->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->date,'invoicedate');
+ }
+ else
{
print dol_print_date($object->date,'daytext');
}
+ }
+ else
+ {
+ print dol_print_date($object->date,'daytext');
+ }
+ print ' | ';
+
+
+ // List of payments
+
+ $sign=1;
+ if ($object->type == 2) $sign=-1;
+
+ $nbrows=8; $nbcols=2;
+ if (! empty($conf->projet->enabled)) $nbrows++;
+ if (! empty($conf->banque->enabled)) $nbcols++;
+ //if (! empty($soc->outstandingbill)) $nbrows++;
+ if($mysoc->localtax1_assuj=="1") $nbrows++;
+ if($mysoc->localtax2_assuj=="1") $nbrows++;
+ if ($selleruserevenustamp) $nbrows++;
+
+ print '';
+
+ print '';
+
+ // List of payments already done
+ print '';
+ print '| '.($object->type == 2 ? $langs->trans("PaymentsBack") : $langs->trans('Payments')).' | ';
+ print ''.$langs->trans('Type').' | ';
+ if (! empty($conf->banque->enabled)) print ''.$langs->trans('BankAccount').' | ';
+ print ''.$langs->trans('Amount').' | ';
+ print ' | ';
+ print ' ';
+
+ $var=true;
+
+ // Payments already done (from payment on this invoice)
+ $sql = 'SELECT p.datep as dp, p.num_paiement, p.rowid, p.fk_bank,';
+ $sql.= ' c.code as payment_code, c.libelle as payment_label,';
+ $sql.= ' pf.amount,';
+ $sql.= ' ba.rowid as baid, ba.ref, ba.label';
+ $sql.= ' FROM '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement_facture as pf, '.MAIN_DB_PREFIX.'paiement 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 pf.fk_facture = '.$object->id.' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid';
+ $sql.= ' ORDER BY p.datep, p.tms';
+
+ $result = $db->query($sql);
+ if ($result)
+ {
+ $num = $db->num_rows($result);
+ $i = 0;
+
+ //if ($object->type != 2)
+ //{
+ if ($num > 0)
+ {
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object($result);
+ $var=!$var;
+ print '| ';
+ print ''.img_object($langs->trans('ShowPayment'),'payment').' ';
+ print dol_print_date($db->jdate($objp->dp),'day').' | ';
+ $label=($langs->trans("PaymentType".$objp->payment_code)!=("PaymentType".$objp->payment_code))?$langs->trans("PaymentType".$objp->payment_code):$objp->payment_label;
+ print ''.$label.' '.$objp->num_paiement.' | ';
+ if (! empty($conf->banque->enabled))
+ {
+ $bankaccountstatic->id=$objp->baid;
+ $bankaccountstatic->ref=$objp->ref;
+ $bankaccountstatic->label=$objp->ref;
+ print '';
+ if ($bankaccountstatic->id) print $bankaccountstatic->getNomUrl(1,'transactions');
+ print ' | ';
+ }
+ print ''.price($sign * $objp->amount).' | ';
+ print ' | ';
+ print ' ';
+ $i++;
+ }
+ }
+ else
+ {
+ print '| '.$langs->trans("None").' | | | ';
+ }
+ //}
+ $db->free($result);
+ }
+ else
+ {
+ dol_print_error($db);
+ }
+
+ if ($object->type != 2)
+ {
+ // Total already paid
+ print '| ';
+ if ($object->type != 3) print $langs->trans('AlreadyPaidNoCreditNotesNoDeposits');
+ else print $langs->trans('AlreadyPaid');
+ print ' : | '.price($totalpaye).' | | ';
+
+ $resteapayeraffiche=$resteapayer;
+
+ // Loop on each credit note or deposit amount applied
+ $creditnoteamount=0;
+ $depositamount=0;
+ $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
+ $sql.= " re.description, re.fk_facture_source";
+ $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re";
+ $sql.= " WHERE fk_facture = ".$object->id;
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ $i = 0;
+ $invoice=new Facture($db);
+ while ($i < $num)
+ {
+ $obj = $db->fetch_object($resql);
+ $invoice->fetch($obj->fk_facture_source);
+ print '| ';
+ if ($invoice->type == 2) print $langs->trans("CreditNote").' ';
+ if ($invoice->type == 3) print $langs->trans("Deposit").' ';
+ print $invoice->getNomUrl(0);
+ print ' : | ';
+ print ''.price($obj->amount_ttc).' | ';
+ print '';
+ print 'id.'&action=unlinkdiscount&discountid='.$obj->rowid.'">'.img_delete().'';
+ print ' | ';
+ $i++;
+ if ($invoice->type == 2) $creditnoteamount += $obj->amount_ttc;
+ if ($invoice->type == 3) $depositamount += $obj->amount_ttc;
+ }
+ }
+ else
+ {
+ dol_print_error($db);
+ }
+
+ // Paye partiellement 'escompte'
+ if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'discount_vat')
+ {
+ print '| ';
+ print $form->textwithpicto($langs->trans("Discount").':',$langs->trans("HelpEscompte"),-1);
+ print ' | '.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' | | ';
+ $resteapayeraffiche=0;
+ }
+ // Paye partiellement ou Abandon 'badcustomer'
+ if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'badcustomer')
+ {
+ print '| ';
+ print $form->textwithpicto($langs->trans("Abandoned").':',$langs->trans("HelpAbandonBadCustomer"),-1);
+ print ' | '.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' | | ';
+ //$resteapayeraffiche=0;
+ }
+ // Paye partiellement ou Abandon 'product_returned'
+ if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'product_returned')
+ {
+ print '| ';
+ print $form->textwithpicto($langs->trans("ProductReturned").':',$langs->trans("HelpAbandonProductReturned"),-1);
+ print ' | '.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' | | ';
+ $resteapayeraffiche=0;
+ }
+ // Paye partiellement ou Abandon 'abandon'
+ if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'abandon')
+ {
+ print '';
+ $text=$langs->trans("HelpAbandonOther");
+ if ($object->close_note) $text.='
'.$langs->trans("Reason").':'.$object->close_note;
+ print $form->textwithpicto($langs->trans("Abandoned").':',$text,-1);
+ print ' | '.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' | | ';
+ $resteapayeraffiche=0;
+ }
+
+ // Billed
+ print '| '.$langs->trans("Billed").' : | '.price($object->total_ttc).' | | ';
+
+ // Remainder to pay
+ print '| ';
+ if ($resteapayeraffiche >= 0) print $langs->trans('RemainderToPay');
+ else print $langs->trans('ExcessReceived');
+ print ' : | ';
+ print ''.price($resteapayeraffiche).' | ';
+ print ' | ';
+ }
+ else // Credit note
+ {
+ // Total already paid back
+ print '| ';
+ print $langs->trans('AlreadyPaidBack');
+ print ' : | '.price($sign * $totalpaye).' | | ';
+
+ // Billed
+ print '| '.$langs->trans("Billed").' : | '.price($sign * $object->total_ttc).' | | ';
+
+ // Remainder to pay back
+ print '| ';
+ if ($resteapayeraffiche <= 0) print $langs->trans('RemainderToPayBack');
+ else print $langs->trans('ExcessPaydBack');
+ print ' : | ';
+ print ''.price($sign * $resteapayeraffiche).' | ';
+ print ' | ';
+
+ // Sold credit note
+ //print '| '.$langs->trans('TotalTTC').' : | ';
+ //print ''.price($sign * $object->total_ttc).' | | ';
+ }
+
+ print ' ';
+
+ // Margin Infos
+ if (! empty($conf->margin->enabled))
+ {
+ print ' ';
+ $object->displayMarginInfos($object->statut > 0);
+ }
+
+ print ' | ';
+
+ // Conditions de reglement
+ print '| ';
+ print '';
+ print ' | ';
+ if ($object->type != 2)
+ {
+ if ($action == 'editconditions')
+ {
+ $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->cond_reglement_id,'cond_reglement_id');
+ }
+ else
+ {
+ $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->cond_reglement_id,'none');
+ }
+ }
+ else
+ {
+ print ' ';
+ }
+ print ' | ';
+
+ // Date payment term
+ print '';
+ print '| ';
+ print $langs->trans('DateMaxPayment');
+ print ' | ';
+ if ($object->type != 2 && $action != 'editpaymentterm' && ! empty($object->brouillon) && $user->rights->facture->creer) print 'id.'">'.img_edit($langs->trans('SetDate'),1).' | ';
+ print ' ';
+ print ' | ';
+ if ($object->type != 2)
+ {
+ if ($action == 'editpaymentterm')
+ {
+ $form->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->date_lim_reglement,'paymentterm');
+ }
+ else
+ {
+ print dol_print_date($object->date_lim_reglement,'daytext');
+ if ($object->date_lim_reglement < ($now - $conf->facture->client->warning_delay) && ! $object->paye && $object->statut == 1 && ! isset($object->am)) print img_warning($langs->trans('Late'));
+ }
+ }
+ else
+ {
+ print ' ';
+ }
+ print ' | ';
+
+ // Payment mode
+ print '| ';
+ print '';
+ print ' | ';
+ if ($action == 'editmode')
+ {
+ $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->mode_reglement_id,'mode_reglement_id');
+ }
+ else
+ {
+ $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->mode_reglement_id,'none');
+ }
+ print ' | ';
+
+ // Amount
+ print '| '.$langs->trans('AmountHT').' | ';
+ print ''.price($object->total_ht,1,'',1,-1,-1,$conf->currency).' | ';
+ print '| '.$langs->trans('AmountVAT').' | '.price($object->total_tva,1,'',1,-1,-1,$conf->currency).' | ';
+ print '';
+
+ // Amount Local Taxes
+ if ($mysoc->localtax1_assuj=="1" && $mysoc->useLocalTax(1)) //Localtax1 (example RE)
+ {
+ print '| '.$langs->transcountry("AmountLT1",$mysoc->country_code).' | ';
+ print ''.price($object->total_localtax1,1,'',1,-1,-1,$conf->currency).' | ';
+ }
+ if ($mysoc->localtax2_assuj=="1" && $mysoc->useLocalTax(2)) //Localtax2 (example IRPF)
+ {
+ print '| '.$langs->transcountry("AmountLT2",$mysoc->country_code).' | ';
+ print ''.price($object->total_localtax2,1,'',1,-1,-1,$conf->currency).' | ';
+ }
+
+ // Revenue stamp
+ if ($selleruserevenustamp) // Test company use revenue stamp
+ {
+ print '| ';
+ print '';
+ print ' | ';
+ if ($action == 'editrevenuestamp')
+ {
+ print '';
+ }
+ else
+ {
+ print price($object->revenuestamp,1,'',1,-1,-1,$conf->currency);
+ }
+ print ' | ';
+ }
+ // Total with tax
+ print '| '.$langs->trans('AmountTTC').' | '.price($object->total_ttc,1,'',1,-1,-1,$conf->currency).' | ';
- // List of payments
+ // Statut
+ print '| '.$langs->trans('Status').' | ';
+ print ''.($object->getLibStatut(4,$totalpaye)).' | ';
- $sign=1;
- if ($object->type == 2) $sign=-1;
+ // Project
+ if (! empty($conf->projet->enabled))
+ {
+ $langs->load('projects');
+ print '';
+ print '| ';
- $nbrows=8; $nbcols=2;
- if (! empty($conf->projet->enabled)) $nbrows++;
- if (! empty($conf->banque->enabled)) $nbcols++;
- //if (! empty($soc->outstandingbill)) $nbrows++;
- if($mysoc->localtax1_assuj=="1") $nbrows++;
- if($mysoc->localtax2_assuj=="1") $nbrows++;
- if ($selleruserevenustamp) $nbrows++;
+ print '';
- print ' | ';
-
- print '';
-
- // List of payments already done
- print '';
- print '| '.($object->type == 2 ? $langs->trans("PaymentsBack") : $langs->trans('Payments')).' | ';
- print ''.$langs->trans('Type').' | ';
- if (! empty($conf->banque->enabled)) print ''.$langs->trans('BankAccount').' | ';
- print ''.$langs->trans('Amount').' | ';
- print ' | ';
+ print '';
+ if ($action == 'classify')
+ {
+ $form->form_project($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->socid,$object->fk_project,'projectid');
+ }
+ else
+ {
+ $form->form_project($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->socid,$object->fk_project,'none');
+ }
+ print ' | ';
print ' ';
+ }
+ // Other attributes (TODO Move this into an include)
+ $res=$object->fetch_optionals($object->id,$extralabels);
+ $parameters=array('colspan' => ' colspan="2"');
+ $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
+ if (empty($reshook) && ! empty($extrafields->attribute_label))
+ {
+
+ foreach($extrafields->attribute_label as $key=>$label)
+ {
+ if ($action == 'edit_extras') {
+ $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
+ } else {
+ $value=$object->array_options["options_".$key];
+ }
+ if ($extrafields->attribute_type[$key] == 'separate')
+ {
+ print $extrafields->showSeparator($key);
+ }
+ else
+ {
+ print '| attribute_required[$key])) print ' class="fieldrequired"';
+ print '>'.$label.' | ';
+ // Convert date into timestamp format
+ if (in_array($extrafields->attribute_type[$key],array('date','datetime')))
+ {
+ $value = isset($_POST["options_".$key])?dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]):$db->jdate($object->array_options['options_'.$key]);
+ }
+
+ if ($action == 'edit_extras' && $user->rights->facture->creer && GETPOST('attribute') == $key)
+ {
+ print '';
+ }
+ else
+ {
+ print $extrafields->showOutputField($key,$value);
+ if ($object->statut == 0 && $user->rights->facture->creer) print ''.img_picto('','edit').' '.$langs->trans('Modify').'';
+ }
+ print ' | '."\n";
+ }
+ }
+ }
+
+ print ' ';
+
+ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
+ {
+ $blocname = 'contacts';
+ $title = $langs->trans('ContactsAddresses');
+ include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
+ }
+
+ if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
+ {
+ $blocname = 'notes';
+ $title = $langs->trans('Notes');
+ include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
+ }
+
+ // Lines
+ $result = $object->getLinesArray();
+
+
+ print ' \n";
+
+ dol_fiche_end();
+
+
+ // Boutons actions
+
+ if ($action != 'prerelance' && $action != 'presend')
+ {
+ if ($user->societe_id == 0 && $action <> 'valid' && $action <> 'editline')
+ {
+ print '';
+
+ // Editer une facture deja validee, sans paiement effectue et pas exporte en compta
+ if ($object->statut == 1)
+ {
+ // On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees
+ $ventilExportCompta = $object->getVentilExportCompta();
+
+ if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0)
{
- $objp = $db->fetch_object($result);
- $var=!$var;
- print ' | ';
- print ''.img_object($langs->trans('ShowPayment'),'payment').' ';
- print dol_print_date($db->jdate($objp->dp),'day').' | ';
- $label=($langs->trans("PaymentType".$objp->payment_code)!=("PaymentType".$objp->payment_code))?$langs->trans("PaymentType".$objp->payment_code):$objp->payment_label;
- print ''.$label.' '.$objp->num_paiement.' | ';
- if (! empty($conf->banque->enabled))
+ if (! $objectidnext)
{
- $bankaccountstatic->id=$objp->baid;
- $bankaccountstatic->ref=$objp->ref;
- $bankaccountstatic->label=$objp->ref;
- print '';
- if ($bankaccountstatic->id) print $bankaccountstatic->getNomUrl(1,'transactions');
- print ' | ';
+ if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->facture->valider) || $user->rights->facture->invoice_advance->unvalidate)
+ {
+ print '';
+ }
+ else
+ {
+ print ''.$langs->trans('Modify').' ';
+ }
}
- print ''.price($sign * $objp->amount).' | ';
- print ' | ';
- print ' ';
- $i++;
+ else
+ {
+ print ' '.$langs->trans('Modify').' ';
+ }
+ }
+ }
+
+ // Reopen a standard paid invoice
+ if (($object->type == 0 || $object->type == 1) && ($object->statut == 2 || $object->statut == 3)) // A paid invoice (partially or completely)
+ {
+ if (! $objectidnext && $object->close_code != 'replaced') // Not replaced by another invoice
+ {
+ print ' ';
+ }
+ else
+ {
+ print ' '.$langs->trans('ReOpen').' ';
+ }
+ }
+
+ // Validate
+ if ($object->statut == 0 && count($object->lines) > 0 &&
+ (
+ (($object->type == 0 || $object->type == 1 || $object->type == 3 || $object->type == 4) && (! empty($conf->global->FACTURE_ENABLE_NEGATIVE) || $object->total_ttc >= 0))
+ || ($object->type == 2 && $object->total_ttc <= 0))
+ )
+ {
+ if ($user->rights->facture->valider)
+ {
+ print ' ';
+ }
+ }
+
+ // Send by mail
+ if (($object->statut == 1 || $object->statut == 2))
+ {
+ if ($objectidnext)
+ {
+ print ' '.$langs->trans('SendByMail').' ';
+ }
+ else
+ {
+ if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send)
+ {
+ print ' ';
+ }
+ else print ' ';
+ }
+ }
+
+ if (! empty($conf->global->FACTURE_SHOW_SEND_REMINDER)) // For backward compatibility
+ {
+ if (($object->statut == 1 || $object->statut == 2) && $resteapayer > 0)
+ {
+ if ($objectidnext)
+ {
+ print ' '.$langs->trans('SendRemindByMail').' ';
+ }
+ else
+ {
+ if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send)
+ {
+ print ' ';
+ }
+ else print ' ';
+ }
+ }
+ }
+
+ // Create payment
+ if ($object->type != 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement)
+ {
+ if ($objectidnext)
+ {
+ print ' '.$langs->trans('DoPayment').' ';
+ }
+ else
+ {
+ if ($resteapayer == 0)
+ {
+ print ' '.$langs->trans('DoPayment').' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ }
+ }
+
+ // Reverse back money or convert to reduction
+ if ($object->type == 2 || $object->type == 3)
+ {
+ // For credit note only
+ if ($object->type == 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement)
+ {
+ print ' ';
+ }
+ // For credit note
+ if ($object->type == 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->creer && $object->getSommePaiement() == 0)
+ {
+ print ' ';
+ }
+ // For deposit invoice
+ if ($object->type == 3 && $object->statut == 1 && $resteapayer == 0 && $user->rights->facture->creer)
+ {
+ print ' ';
+ }
+ }
+
+ // Classify paid (if not deposit and not credit note. Such invoice are "converted")
+ if ($object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement &&
+ (($object->type != 2 && $object->type != 3 && $resteapayer <= 0) || ($object->type == 2 && $resteapayer >= 0)) )
+ {
+ print ' ';
+ }
+
+ // Classify 'closed not completely paid' (possible si validee et pas encore classee payee)
+ if ($object->statut == 1 && $object->paye == 0 && $resteapayer > 0
+ && $user->rights->facture->paiement)
+ {
+ if ($totalpaye > 0 || $totalcreditnotes > 0)
+ {
+ // If one payment or one credit note was linked to this invoice
+ print ' ';
+ }
+ else
+ {
+ if ($objectidnext)
+ {
+ print ' '.$langs->trans('ClassifyCanceled').' ';
+ }
+ else
+ {
+ print ' ';
+ }
+ }
+ }
+
+ // Clone
+ if (($object->type == 0 || $object->type == 3 || $object->type == 4) && $user->rights->facture->creer)
+ {
+ print ' ';
+ }
+
+ // Clone as predefined
+ if (($object->type == 0 || $object->type == 3 || $object->type == 4) && $object->statut == 0 && $user->rights->facture->creer)
+ {
+ if (! $objectidnext)
+ {
+ print ' ';
+ }
+ }
+
+ // Delete
+ if ($user->rights->facture->supprimer)
+ {
+ if (! $object->is_erasable())
+ {
+ print ' ';
+ }
+ else if ($objectidnext)
+ {
+ print ' ';
+ }
+ elseif ($object->getSommePaiement())
+ {
+ print ' ';
+ }
+ else
+ {
+ print ' ';
}
}
else
{
- print ' | '.$langs->trans("None").' | | | ';
+ print ' ';
}
- //}
- $db->free($result);
+
+ print ' ';
+ }
+ }
+ print ' ';
+
+ if ($action != 'prerelance' && $action != 'presend')
+ {
+ print '';
+ print ' '; // ancre
+
+ // Documents generes
+ $filename=dol_sanitizeFileName($object->ref);
+ $filedir=$conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref);
+ $urlsource=$_SERVER['PHP_SELF'].'?facid='.$object->id;
+ $genallowed=$user->rights->facture->creer;
+ $delallowed=$user->rights->facture->supprimer;
+
+ print $formfile->showdocuments('facture',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
+ $somethingshown=$formfile->numoffiles;
+
+ // Linked object block
+ $somethingshown=$object->showLinkedObjectBlock();
+
+ if (empty($somethingshown) && $object->statut > 0)
+ {
+ print ' '.$langs->trans('LinkedOrder').'';
+
+ print ' ';
+
+ $sql = "SELECT s.rowid as socid, s.nom as name, s.client, c.rowid, c.ref, c.ref_client, c.total_ht";
+ $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
+ $sql.= ", ".MAIN_DB_PREFIX."commande as c";
+ $sql.= ' WHERE c.fk_soc = '.$soc->id.'';
+
+ $resqlorderlist = $db->query($sql);
+ if ($resqlorderlist)
+ {
+ $num = $db->num_rows($resqlorderlist);
+ $i = 0;
+
+ print ' ';
+ $db->free($resqlorderlist);
}
else
{
dol_print_error($db);
}
- if ($object->type != 2)
- {
- // Total already paid
- print ' | ';
- if ($object->type != 3) print $langs->trans('AlreadyPaidNoCreditNotesNoDeposits');
- else print $langs->trans('AlreadyPaid');
- print ' : | '.price($totalpaye).' | | ';
+ print ' ';
+ }
- $resteapayeraffiche=$resteapayer;
+ // Link for paypal payment
+ if (! empty($conf->paypal->enabled) && $object->statut != 0)
+ {
+ include_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
+ print showPaypalPaymentUrl('invoice',$object->ref);
+ }
- // Loop on each credit note or deposit amount applied
- $creditnoteamount=0;
- $depositamount=0;
- $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
- $sql.= " re.description, re.fk_facture_source";
- $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re";
- $sql.= " WHERE fk_facture = ".$object->id;
- $resql=$db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
- $i = 0;
- $invoice=new Facture($db);
- while ($i < $num)
- {
- $obj = $db->fetch_object($resql);
- $invoice->fetch($obj->fk_facture_source);
- print ' | ';
- if ($invoice->type == 2) print $langs->trans("CreditNote").' ';
- if ($invoice->type == 3) print $langs->trans("Deposit").' ';
- print $invoice->getNomUrl(0);
- print ' : | ';
- print ''.price($obj->amount_ttc).' | ';
- print '';
- print 'id.'&action=unlinkdiscount&discountid='.$obj->rowid.'">'.img_delete().'';
- print ' | ';
- $i++;
- if ($invoice->type == 2) $creditnoteamount += $obj->amount_ttc;
- if ($invoice->type == 3) $depositamount += $obj->amount_ttc;
- }
- }
- else
- {
- dol_print_error($db);
- }
+ print ' ';
- // Paye partiellement 'escompte'
- if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'discount_vat')
- {
- print ' | ';
- print $form->textwithpicto($langs->trans("Discount").':',$langs->trans("HelpEscompte"),-1);
- print ' | '.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' | | ';
- $resteapayeraffiche=0;
- }
- // Paye partiellement ou Abandon 'badcustomer'
- if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'badcustomer')
- {
- print '| ';
- print $form->textwithpicto($langs->trans("Abandoned").':',$langs->trans("HelpAbandonBadCustomer"),-1);
- print ' | '.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' | | ';
- //$resteapayeraffiche=0;
- }
- // Paye partiellement ou Abandon 'product_returned'
- if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'product_returned')
- {
- print '| ';
- print $form->textwithpicto($langs->trans("ProductReturned").':',$langs->trans("HelpAbandonProductReturned"),-1);
- print ' | '.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' | | ';
- $resteapayeraffiche=0;
- }
- // Paye partiellement ou Abandon 'abandon'
- if (($object->statut == 2 || $object->statut == 3) && $object->close_code == 'abandon')
- {
- print '';
- $text=$langs->trans("HelpAbandonOther");
- if ($object->close_note) $text.='
'.$langs->trans("Reason").':'.$object->close_note;
- print $form->textwithpicto($langs->trans("Abandoned").':',$text,-1);
- print ' | '.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' | | ';
- $resteapayeraffiche=0;
- }
+ // List of actions on element
+ include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
+ $formactions=new FormActions($db);
+ $somethingshown=$formactions->showactions($object,'invoice',$socid);
- // Billed
- print '| '.$langs->trans("Billed").' : | '.price($object->total_ttc).' | | ';
-
- // Remainder to pay
- print '| ';
- if ($resteapayeraffiche >= 0) print $langs->trans('RemainderToPay');
- else print $langs->trans('ExcessReceived');
- print ' : | ';
- print ''.price($resteapayeraffiche).' | ';
- print ' | ';
- }
- else // Credit note
- {
- // Total already paid back
- print '| ';
- print $langs->trans('AlreadyPaidBack');
- print ' : | '.price($sign * $totalpaye).' | | ';
-
- // Billed
- print '| '.$langs->trans("Billed").' : | '.price($sign * $object->total_ttc).' | | ';
-
- // Remainder to pay back
- print '| ';
- if ($resteapayeraffiche <= 0) print $langs->trans('RemainderToPayBack');
- else print $langs->trans('ExcessPaydBack');
- print ' : | ';
- print ''.price($sign * $resteapayeraffiche).' | ';
- print ' | ';
-
- // Sold credit note
- //print '| '.$langs->trans('TotalTTC').' : | ';
- //print ''.price($sign * $object->total_ttc).' | | ';
- }
-
- print ' | ';
-
- // Margin Infos
- if (! empty($conf->margin->enabled))
- {
- print ' ';
- $object->displayMarginInfos($object->statut > 0);
- }
-
- print ' |
';
-
- // Conditions de reglement
- print '