Debut gestion des avoirs

This commit is contained in:
Laurent Destailleur 2006-10-07 00:16:18 +00:00
parent 151613496e
commit 21450a9234
5 changed files with 175 additions and 20 deletions

View File

@ -79,6 +79,33 @@ $NBLINES=4;
* Actions
*/
// Validation
if ($_GET['action'] == 'valid')
{
$facture = new Facture($db);
$facture->fetch($_GET['facid']);
// On verifie signe facture
if ($facture->type == 2)
{
// Si avoir, le signe doit etre négatif
if ($facture->total_ht >= 0)
{
$mesg='<div class="error">'.$langs->trans("ErrorInvoiceAvoirMustBeNegative").'</div>';
$_GET['action']='';
}
}
else
{
// Si non avoir, le signe doit etre positif
if ($facture->total_ht < 0)
{
$mesg='<div class="error">'.$langs->trans("ErrorInvoiceOfThisTypeMustBePositive").'</div>';
$_GET['action']='';
}
}
}
if ($_POST['action'] == 'classin')
{
$facture = new Facture($db);
@ -275,6 +302,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer)
$db->begin();
// Facture remplacement
if ($_POST['type'] == 1)
{
if ($_POST['fac_replacement'] > 0)
@ -308,6 +336,42 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer)
}
}
// Facture avoir
if ($_POST['type'] == 2)
{
if ($_POST['fac_avoir'] > 0)
{
// Si facture avoir
$datefacture = mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
//$result=$facture->fetch($_POST['fac_avoir']);
$facture->socid = $_POST['socid'];
$facture->number = $_POST['facnumber'];
$facture->date = $datefacture;
$facture->note_public = trim($_POST['note_public']);
$facture->note = trim($_POST['note']);
$facture->ref_client = $_POST['ref_client'];
$facture->modelpdf = $_POST['model'];
$facture->projetid = $_POST['projetid'];
$facture->cond_reglement_id = 0;
$facture->mode_reglement_id = $_POST['mode_reglement_id'];
$facture->remise_absolue = $_POST['remise_absolue'];
$facture->remise_percent = $_POST['remise_percent'];
// Propriétés particulieres a facture avoir
$facture->fk_facture_source = $_POST['fac_avoir'];
$facture->type = 2;
$facid = $facture->create($user);
}
else
{
$error=1;
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("CorrectInvoice")).'</div>';
}
}
if ($_POST['type'] == 0 && $_POST['fac_rec'] > 0)
{
// Si facture récurrente
@ -322,7 +386,10 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer)
$facture->ref_client = $_POST['ref_client'];
$facture->modelpdf = $_POST['model'];
// Propriétés particulieres a facture recurrente
$facture->fac_rec = $_POST['fac_rec'];
$facture->type = 3;
$facid = $facture->create($user);
}
@ -1029,7 +1096,7 @@ if ($_GET['action'] == 'create')
/*
\todo
L'info "Reference commande client" est une carac de la commande et non de la facture.
Elle devrait donc etre stockée sur l'objet commande lié à la facture et non sur la facture.
Elle devrait donc etre stockée sur l'objet commande liée à la facture et non sur la facture.
Pour ceux qui veulent l'utiliser au niveau de la facture, positionner la
constante FAC_USE_CUSTOMER_ORDER_REF à 1.
*/
@ -1039,7 +1106,7 @@ if ($_GET['action'] == 'create')
print '<input type="text" name="ref_client" value="'.$ref_client.'">';
print '</td></tr>';
}
// Societe
print '<tr><td>'.$langs->trans('Company').'</td><td colspan="2">';
print $soc->getNomUrl(1);
@ -1054,6 +1121,13 @@ if ($_GET['action'] == 'create')
{
$options.='<option value="'.$key.'">'.$value.'</option>';
}
$facids=$facturestatic->list_avoir_invoices($soc->id);
$optionsav="";
foreach ($facids as $key => $value)
{
$optionsav.='<option value="'.$key.'">'.$value.'</option>';
}
print '<tr><td valign="top">'.$langs->trans('Type').'</td><td colspan="2">';
print '<table class="nobordernopadding"><tr>';
print '<td width="16px">';
@ -1062,13 +1136,16 @@ if ($_GET['action'] == 'create')
$desc=$html->textwithhelp($langs->trans("InvoiceStandardAsk"),$langs->transnoentities("InvoiceStandardDesc"),1);
print $desc;
print '</td></tr>';
print '<tr><td>';
print '<input type="radio" name="type" value="1"'.($_POST['type']==1?' checked=true':'');
if (! $options) print ' disabled="true"';
print '>';
print '</td><td>';
$text=$langs->trans("InvoiceReplacementAsk").' ';
$text.='<select name="fac_replacement">';
$text.='<select class="flat" name="fac_replacement"';
if (! $options) $text.=' disabled="true"';
$text.='>';
if ($options)
{
$text.='<option value="-1">&nbsp;</option>';
@ -1082,10 +1159,29 @@ if ($_GET['action'] == 'create')
$desc=$html->textwithhelp($text,$langs->transnoentities("InvoiceReplacementDesc"),1);
print $desc;
print '</td></tr>';
print '<tr><td>';
print '<input type="radio" name="type" value="2"'.($_POST['type']==2?' checked=true':'').' disabled>';
print '<input type="radio" name="type" value="2"'.($_POST['type']==2?' checked=true':'');
if (! $optionsav) print ' disabled="true"';
print '>';
print '</td><td>';
$desc=$html->textwithhelp($langs->trans("InvoiceAvoirAsk").' ('.$langs->trans("FeatureNotYetAvailable").')',$langs->transnoentities("InvoiceAvoirDesc"),1);
$text=$langs->transnoentities("InvoiceAvoirAsk").' ';
// $text.='<input type="text" value="">';
$text.='<select class="flat" name="fac_avoir"';
if (! $options) $text.=' disabled="true"';
$text.='>';
if ($options)
{
$text.='<option value="-1">&nbsp;</option>';
$text.=$optionsav;
}
else
{
$text.='<option value="-1">'.$langs->trans("NoInvoiceToCorrect").'</option>';
}
$text.='</select>';
$desc=$html->textwithhelp($text,$langs->transnoentities("InvoiceAvoirDesc"),1);
//.' ('.$langs->trans("FeatureNotYetAvailable").')',$langs->transnoentities("InvoiceAvoirDesc"),1);
print $desc;
print '</td></tr>';
print '</table>';
@ -1642,6 +1738,12 @@ else
$facreplaced->fetch($fac->fk_facture_source);
print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')';
}
if ($fac->type == 2)
{
$facreplaced=new Facture($db);
$facreplaced->fetch($fac->fk_facture_source);
print ' ('.$langs->transnoentities("CorrectInvoice",$facreplaced->getNomUrl(1)).')';
}
$facidnext=$fac->getIdReplacingInvoice();
if ($facidnext > 0)
{

View File

@ -50,13 +50,14 @@ class Facture extends CommonObject
var $id;
var $socid; // Id client
var $client; // Objet societe client (à charger par fetch_client)
var $client; // Objet societe client (à charger par fetch_client)
var $number;
var $author;
var $date;
var $ref;
var $ref_client;
var $type; // 0=Facture normale, 1=Facture remplacement, 2=Facture avoir, 3=Facture récurrente
var $amount;
var $remise;
var $tva;
@ -2231,6 +2232,46 @@ class Facture extends CommonObject
}
}
/**
* \brief Renvoi liste des factures qualifiables pour avoir
* Statut validee + pas deja remplacées
* \param socid Id societe
* \return array Tableau des factures ($id => $ref)
*/
function list_avoir_invoices($socid=0)
{
global $conf;
$return = array();
$sql = "SELECT f.rowid as rowid, f.facnumber";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
$sql.= " WHERE f.fk_statut >= 1 AND f.paye = 0";
if ($socid > 0) $sql.=" AND f.fk_soc = ".$socid;
$sql.= " ORDER BY f.facnumber";
dolibarr_syslog("Facture.class::list_avoir_invoices sql=$sql");
$resql=$this->db->query($sql);
if ($resql)
{
while ($obj=$this->db->fetch_object($resql))
{
$return[$obj->rowid]=$obj->facnumber;
}
return $return;
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Facture.class::list_avoir_invoices ".$this->error);
return -1;
}
}
/**
* \brief Créé une demande de prélèvement
* \param user Utilisateur créant la demande

View File

@ -496,7 +496,7 @@ class pdf_crabe extends ModelePDFFactures
/*
* Conditions de règlements
*/
if ($object->cond_reglement_code || $object->cond_reglement)
if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement))
{
$pdf->SetFont('Arial','B',8);
$pdf->SetXY($this->marge_gauche, $posy);
@ -514,7 +514,7 @@ class pdf_crabe extends ModelePDFFactures
/*
* Check si absence mode règlement
*/
if (! $conf->global->FACTURE_CHQ_NUMBER && ! $conf->global->FACTURE_RIB_NUMBER)
if ($object->type != 2 && (! $conf->global->FACTURE_CHQ_NUMBER && ! $conf->global->FACTURE_RIB_NUMBER))
{
$pdf->SetXY($this->marge_gauche, $posy);
$pdf->SetTextColor(200,0,0);
@ -528,7 +528,7 @@ class pdf_crabe extends ModelePDFFactures
/*
* Propose mode règlement par CHQ
*/
if (! $object->mode_reglement_code || $object->mode_reglement_code == 'CHQ')
if ($object->type != 2 && (! $object->mode_reglement_code || $object->mode_reglement_code == 'CHQ'))
{
// Si mode reglement non force ou si force a CHQ
if ($conf->global->FACTURE_CHQ_NUMBER)
@ -568,7 +568,7 @@ class pdf_crabe extends ModelePDFFactures
/*
* Propose mode règlement par RIB
*/
if (! $object->mode_reglement_code || $object->mode_reglement_code == 'VIR')
if ($object->type != 2 && (! $object->mode_reglement_code || $object->mode_reglement_code == 'VIR'))
{
// Si mode reglement non force ou si force a VIR
if ($conf->global->FACTURE_RIB_NUMBER)
@ -651,7 +651,7 @@ class pdf_crabe extends ModelePDFFactures
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->trans("TotalHT"), 0, 'L', 1);
$pdf->SetXY ($col2x, $tab2_top + 0);
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ht + $object->remise), 0, 'R', 1);
$pdf->MultiCell($largcol2, $tab2_hl, price(abs($object->total_ht + $object->remise)), 0, 'R', 1);
// Remise globale
if ($object->remise > 0)
@ -666,7 +666,7 @@ class pdf_crabe extends ModelePDFFactures
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->trans("WithDiscountTotalHT"), 0, 'L', 1);
$pdf->SetXY ($col2x, $tab2_top + $tab2_hl * 2);
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ht), 0, 'R', 1);
$pdf->MultiCell($largcol2, $tab2_hl, price(abs($object->total_ht)), 0, 'R', 1);
$index = 2;
}
@ -689,7 +689,7 @@ class pdf_crabe extends ModelePDFFactures
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->trans("TotalVAT").' '.abs($tvakey).'%'.$tvacompl, 0, 'L', 1);
$pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval * (float)$tvakey / 100 ), 0, 'R', 1);
$pdf->MultiCell($largcol2, $tab2_hl, price(abs($tvaval * (float)$tvakey / 100 )), 0, 'R', 1);
}
}
if (! $this->atleastoneratenotnull)
@ -699,7 +699,7 @@ class pdf_crabe extends ModelePDFFactures
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->trans("TotalVAT"), 0, 'L', 1);
$pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1);
$pdf->MultiCell($largcol2, $tab2_hl, price(abs($object->total_tva)), 0, 'R', 1);
}
$useborder=0;
@ -708,10 +708,12 @@ class pdf_crabe extends ModelePDFFactures
$pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index);
$pdf->SetTextColor(0,0,60);
$pdf->SetFillColor(224,224,224);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->trans("TotalTTC"), $useborder, 'L', 1);
$text=$outputlangs->trans("TotalTTC");
if ($object->type == 2) $text=$outputlangs->trans("TotalTTCToYourCredit");
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $text, $useborder, 'L', 1);
$pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc), $useborder, 'R', 1);
$pdf->MultiCell($largcol2, $tab2_hl, price(abs($object->total_ttc)), $useborder, 'R', 1);
$pdf->SetTextColor(0,0,0);
if ($deja_regle > 0)
@ -736,7 +738,7 @@ class pdf_crabe extends ModelePDFFactures
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->trans("EscompteOffered"), $useborder, 'L', 1);
$pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle), $useborder, 'R', 1);
$pdf->MultiCell($largcol2, $tab2_hl, price(abs($object->total_ttc - $deja_regle)), $useborder, 'R', 1);
}
$index++;
@ -746,7 +748,7 @@ class pdf_crabe extends ModelePDFFactures
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->trans("RemainderToPay"), $useborder, 'L', 1);
$pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1);
$pdf->MultiCell($largcol2, $tab2_hl, price(abs($resteapayer)), $useborder, 'R', 1);
// Fin
$pdf->SetFont('Arial','', 9);

View File

@ -15,11 +15,13 @@ InvoiceReplacement=Replacement invoice. Must replace invoice with reference
InvoiceReplacementAsk=Replacement invoice for invoice
InvoiceReplacementDesc=<b>Replacement invoice</b> is used to cancel and replace completely an invoice with no paiement already recevided.<br>Reference of canceled invoice is required.
InvoiceAvoir=Avoir invoice
InvoiceAvoirAsk=Avoir invoice
InvoiceAvoirAsk=Avoir invoice to correct invoice
InvoiceAvoirDesc=La <b>facture d'avoir</b> est une facture négative destinée à compenser une facture comportant un montant supérieur à ce qui a été ou sera réellement payé (toutes causes possibles).
ReplaceInvoice=Replace invoice %s
ReplacedByInvoice=Replaced by invoice %s
CorrectInvoice=Correct invoice %s
NoReplacableInvoice=No replacable invoices
NoInvoiceToCorrect=No invoice to correct
CardBill=Invoice card
Invoice=Invoice
Invoices=Invoices
@ -58,6 +60,7 @@ DoPayment=Do payment
VAT=VAT
VATRate=VAT Rate
Amount=Amount
TotalTTCToYourCredit=Total TTC to your credit
BillStatus=Invoice status
BillStatusDraft=Draft (need to be validated)
BillStatusPayed=Payed
@ -82,6 +85,8 @@ ErrorCreateBankAccount=Creat a bank account then go to Setup panel of Invoice mo
ErrorBillNotFound=Invoice %s does not exists
ErrorInvoiceAlreadyReplaced=Error, invoice %s has already been replaced by invoice %s
ErrorDiscountAlreadyUsed=Error, discount already used
ErrorInvoiceAvoirMustBeNegative=Error, correct invoice must have a negative amount
ErrorInvoiceOfThisTypeMustBePositive=Error, this type of invoice must have a positive amount
BillFrom=From
BillTo=Bill to
ActionsOnBill=Actions on invoice

View File

@ -15,11 +15,13 @@ InvoiceReplacement=Facture de remplacement
InvoiceReplacementAsk=Facture de remplacement de la facture
InvoiceReplacementDesc=La <b>facture de remplacement</b> sert à annuler et remplacer une facture existante sur laquelle aucun paiement n'a encore eu lieu.<br>La référence de la facture qui doit être annulée est obligatoire.
InvoiceAvoir=Facture avoir
InvoiceAvoirAsk=Facture avoir
InvoiceAvoirAsk=Facture avoir pour correction de la facture
InvoiceAvoirDesc=La <b>facture d'avoir</b> est une facture négative destinée à compenser une facture comportant un montant supérieur à ce qui a été ou sera réellement payé (toutes causes possibles).
ReplaceInvoice=Remplace la facture %s
ReplacedByInvoice=Remplacée par la facture %s
CorrectInvoice=Corrige facture %s
NoReplacableInvoice=Pas de factures remplacables
NoInvoiceToCorrect=Pas de factures à corriger
CardBill=Fiche facture
Invoice=Facture
Invoices=Factures
@ -58,6 +60,7 @@ DoPayment=
VAT=TVA
VATRate=Taux TVA
Amount=Montant
TotalTTCToYourCredit=Total TTC à votre crédit
BillStatus=État de la facture
BillStatusDraft=Brouillon (à valider)
BillStatusPayed=Payée
@ -82,6 +85,8 @@ ErrorCreateBankAccount=Cr
ErrorBillNotFound=Facture %s inexistante
ErrorInvoiceAlreadyReplaced=Erreur, la facture %s a déjà été remplacée par la facture %s
ErrorDiscountAlreadyUsed=Erreur, la remise a déjà été attribuée
ErrorInvoiceAvoirMustBeNegative=Erreur, une facture de type Avoir doit avoir un montant négatif
ErrorInvoiceOfThisTypeMustBePositive=Erreur, une facture de ce type doit avoir un montant positif
BillFrom=Émetteur
BillTo=Adressé à
ActionsOnBill=Actions sur la facture