New: Use a function to format address according to country

This commit is contained in:
Laurent Destailleur 2010-09-19 16:25:24 +00:00
parent 2fc71ec5be
commit 0c72d41f36
10 changed files with 451 additions and 482 deletions

View File

@ -875,37 +875,12 @@ class Expedition extends CommonObject
dol_syslog("Expedition::initAsSpecimen"); dol_syslog("Expedition::initAsSpecimen");
// Charge tableau des id de societe socids
$socids = array();
$sql = "SELECT rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."societe";
$sql.= " WHERE client IN (1, 3)";
$sql.= " AND entity = ".$conf->entity;
$sql.= " LIMIT 10";
$resql = $this->db->query($sql);
if ($resql)
{
$num_socs = $this->db->num_rows($resql);
$i = 0;
while ($i < $num_socs)
{
$i++;
$row = $this->db->fetch_row($resql);
$socids[$i] = $row[0];
}
}
// Charge tableau des produits prodids // Charge tableau des produits prodids
$prodids = array(); $prodids = array();
$sql = "SELECT rowid"; $sql = "SELECT rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."product"; $sql.= " FROM ".MAIN_DB_PREFIX."product";
$sql.= " WHERE tosell = 1"; $sql.= " WHERE tosell = 1";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$conf->entity;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -926,7 +901,6 @@ class Expedition extends CommonObject
$this->id=0; $this->id=0;
$this->ref = 'SPECIMEN'; $this->ref = 'SPECIMEN';
$this->specimen=1; $this->specimen=1;
$socid = rand(1, $num_socs);
$this->statut = 1; $this->statut = 1;
if ($conf->livraison_bon->enabled) if ($conf->livraison_bon->enabled)
{ {
@ -935,11 +909,14 @@ class Expedition extends CommonObject
$this->date = time(); $this->date = time();
$this->entrepot_id = 0; $this->entrepot_id = 0;
$this->fk_delivery_address = 0; $this->fk_delivery_address = 0;
$this->socid = $socids[$socid]; $this->socid = 1;
$this->commande_id = 0; $this->commande_id = 0;
$this->commande = $order; $this->commande = $order;
$this->origin_id = 1;
$this->origin = 'commande';
$nbp = 5; $nbp = 5;
$xnbp = 0; $xnbp = 0;
while ($xnbp < $nbp) while ($xnbp < $nbp)

View File

@ -954,8 +954,7 @@ class pdf_einstein extends ModelePDFCommandes
// Show recipient information // Show recipient information
$pdf->SetFont('','',9); $pdf->SetFont('','',9);
$posy=$pdf->GetY()-9; //Auto Y coord readjust for multiline name $pdf->SetXY($posx+2,$posy+8);
$pdf->SetXY($posx+2,$posy+6);
$pdf->MultiCell(86,4, $carac_client); $pdf->MultiCell(86,4, $carac_client);
} }
} }

View File

@ -432,7 +432,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition
// Sender name // Sender name
$pdf->SetTextColor(0,0,60); $pdf->SetTextColor(0,0,60);
$pdf->SetXY($blSocX,$blSocY); $pdf->SetXY($blSocX,$blSocY+3);
$pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->nom), 0, 'L'); $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->nom), 0, 'L');
$pdf->SetTextColor(0,0,0); $pdf->SetTextColor(0,0,0);
@ -440,11 +440,10 @@ Class pdf_expedition_merou extends ModelePdfExpedition
$carac_emetteur = pdf_build_address($outputlangs,$this->emetteur); $carac_emetteur = pdf_build_address($outputlangs,$this->emetteur);
$pdf->SetFont('','',7); $pdf->SetFont('','',7);
$pdf->SetXY($blSocX,$blSocY+3); $pdf->SetXY($blSocX,$blSocY+6);
$pdf->MultiCell(80, 2, $carac_emetteur); $pdf->MultiCell(80, 2, $carac_emetteur);
if ($object->client->code_client) if ($object->client->code_client)
{ {
$Yoff+=7; $Yoff+=7;
@ -523,8 +522,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition
$pdf->MultiCell($blW,3, $carac_client_name, 0, 'L'); $pdf->MultiCell($blW,3, $carac_client_name, 0, 'L');
$pdf->SetFont('','',7); $pdf->SetFont('','',7);
//$posy=$pdf->GetY(); //Auto Y coord readjust for multiline name $pdf->SetXY($blDestX,$Yoff+4);
$pdf->SetXY($blDestX,$pdf->GetY());
$pdf->MultiCell($blW,2, $carac_client); $pdf->MultiCell($blW,2, $carac_client);
} }
} }

View File

@ -1225,8 +1225,7 @@ class pdf_crabe extends ModelePDFFactures
// Show recipient information // Show recipient information
$pdf->SetFont('','',9); $pdf->SetFont('','',9);
$posy=$pdf->GetY()-9; //Auto Y coord readjust for multiline name $pdf->SetXY($posx+2,$posy+8);
$pdf->SetXY($posx+2,$posy+6);
$pdf->MultiCell(86,4, $carac_client, 0, 'L'); $pdf->MultiCell(86,4, $carac_client, 0, 'L');
} }
} }

View File

@ -895,7 +895,7 @@ class pdf_oursin extends ModelePDFFactures
$pdf->MultiCell(86,4, $carac_client_name, 0, 'L'); $pdf->MultiCell(86,4, $carac_client_name, 0, 'L');
$pdf->SetFont('','B',9); $pdf->SetFont('','B',9);
$pdf->SetXY($this->marges['g']+100,$posy+6); $pdf->SetXY($this->marges['g']+100,$posy+8);
$pdf->MultiCell(86,4, $carac_client); $pdf->MultiCell(86,4, $carac_client);
/* /*

View File

@ -646,7 +646,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder
$pdf->MultiCell(106,4, $carac_client_name, 0, 'L'); $pdf->MultiCell(106,4, $carac_client_name, 0, 'L');
$pdf->SetFont('','',9); $pdf->SetFont('','',9);
$pdf->SetXY(102,$posy+7); $pdf->SetXY(102,$posy+8);
$pdf->MultiCell(86,4, $carac_client); $pdf->MultiCell(86,4, $carac_client);
} }

View File

@ -1011,8 +1011,7 @@ class pdf_propale_azur extends ModelePDFPropales
// Show recipient information // Show recipient information
$pdf->SetFont('','',9); $pdf->SetFont('','',9);
$posy=$pdf->GetY()-9; //Auto Y coord readjust for multiline name $pdf->SetXY($posx+2,$posy+8);
$pdf->SetXY($posx+2,$posy+6);
$pdf->MultiCell(86,4, $carac_client); $pdf->MultiCell(86,4, $carac_client);
} }
} }

View File

@ -606,8 +606,7 @@ class pdf_propale_jaune extends ModelePDFPropales
// Show address // Show address
$pdf->SetFont('','',9); $pdf->SetFont('','',9);
$posy=$pdf->GetY()-9; //Auto Y coord readjust for multiline name $pdf->SetXY(102,$posy+8);
$pdf->SetXY(102,$posy+6);
$pdf->MultiCell(86,4, $carac_client); $pdf->MultiCell(86,4, $carac_client);
} }

View File

@ -27,14 +27,52 @@
*/ */
/** /**
* \brief Mutualize code to build address for PDF generation * Return a formated address (part address/zip/town/state) according to country rules
* \param outputlangs Output langs object * @param outputlangs Output langs object
* \param sourcecompany Source company object * @param object A company or contact object
* \param targetcompany Target company object * @return string Formated string
* \param targetcontact Target contact object */
* \param usecontact Use contact instead of company function pdf_format_address($outputlangs,$object)
* \return string Source of file {
$ret='';
$countriesusingstate=array('US','IN');
// Address
$ret .= $outputlangs->convToOutputCharset($object->address);
// Zip/Town/State
if (in_array($object->pays_code,array('US'))) // US: town, state, zip
{
$ret .= ($ret ? "\n" : '' ).$outputlangs->convToOutputCharset($object->ville);
if ($object->departement && in_array($object->pays_code,$countriesusingstate))
{
$ret.=", ".$outputlangs->convToOutputCharset($object->departement);
}
if ($object->cp) $ret .= ', '.$outputlangs->convToOutputCharset($object->cp);
}
else // Other: zip town, state
{
$ret .= ($ret ? "\n" : '' ).$outputlangs->convToOutputCharset($object->cp);
$ret .= ' '.$outputlangs->convToOutputCharset($object->ville);
if ($object->departement && in_array($object->pays_code,$countriesusingstate))
{
$ret.=", ".$outputlangs->convToOutputCharset($object->departement);
}
}
return $ret;
}
/**
* Return a string with full address formated
* @param outputlangs Output langs object
* @param sourcecompany Source company object
* @param targetcompany Target company object
* @param targetcontact Target contact object
* @param usecontact Use contact instead of company
* @return string Source of file
*/ */
function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$targetcontact='',$usecontact=0,$mode='source') function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$targetcontact='',$usecontact=0,$mode='source')
{ {
@ -45,16 +83,13 @@ function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$target
if ($mode == 'source' && ! is_object($sourcecompany)) return -1; if ($mode == 'source' && ! is_object($sourcecompany)) return -1;
if ($mode == 'target' && ! is_object($targetcompany)) return -1; if ($mode == 'target' && ! is_object($targetcompany)) return -1;
if ($sourcecompany->departement_id && empty($sourcecompany->departement)) $sourcecompany->departement=getState($sourcecompany->departement_id);
if ($targetcompany->departement_id && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->departement_id);
if ($mode == 'source') if ($mode == 'source')
{ {
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($sourcecompany->address); $stringaddress .= ($stringaddress ? "\n" : '' ).pdf_format_address($outputlangs,$sourcecompany)."\n";
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($sourcecompany->cp).' '.$outputlangs->convToOutputCharset($sourcecompany->ville);
if (($sourcecompany->departement_id || $sourcecompany->departement) && in_array($sourcecompany->pays_code,array('US','IN')))
{
if ($sourcecompany->departement_id && empty($sourcecompany->departement)) $sourcecompany->departement=getState($sourcecompany->departement_id);
$stringaddress.=" - ".$outputlangs->convToOutputCharset($sourcecompany->departement);
}
$stringaddress .= "\n";
// Tel // Tel
if ($sourcecompany->tel) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ".$outputlangs->convToOutputCharset($sourcecompany->tel); if ($sourcecompany->tel) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ".$outputlangs->convToOutputCharset($sourcecompany->tel);
// Fax // Fax
@ -69,33 +104,22 @@ function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$target
{ {
if ($usecontact) if ($usecontact)
{ {
$stringaddress.="\n".$outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs,1)); $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs,1));
// Recipient properties $stringaddress .= ($stringaddress ? "\n" : '' ).pdf_format_address($outputlangs,$targetcontact)."\n";
$stringaddress.="\n".$outputlangs->convToOutputCharset($targetcontact->address); // Country
$stringaddress.="\n".$outputlangs->convToOutputCharset($targetcontact->cp) . " " . $outputlangs->convToOutputCharset($targetcontact->ville);
if (($targetcompany->departement_id || $targetcompany->departement) && in_array($targetcompany->pays_code,array('US','IN')))
{
if ($targetcompany->departement_id && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->departement_id);
$stringaddress.=" - ".$outputlangs->convToOutputCharset($targetcompany->departement);
}
$stringaddress.="\n";
if ($targetcontact->pays_code && $targetcontact->pays_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->pays_code))."\n"; if ($targetcontact->pays_code && $targetcontact->pays_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->pays_code))."\n";
} }
else else
{ {
// Recipient properties $stringaddress .= ($stringaddress ? "\n" : '' ).pdf_format_address($outputlangs,$targetcompany)."\n";
$stringaddress.="\n".$outputlangs->convToOutputCharset($targetcompany->address); // Country
$stringaddress.="\n".$outputlangs->convToOutputCharset($targetcompany->cp) . " " . $outputlangs->convToOutputCharset($targetcompany->ville);
if (($targetcompany->departement_id || $targetcompany->departement) && in_array($targetcompany->pays_code,array('US','IN')))
{
if ($targetcompany->departement_id && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->departement_id);
$stringaddress.=" - ".$outputlangs->convToOutputCharset($targetcompany->departement);
}
$stringaddress.="\n";
if ($targetcompany->pays_code && $targetcompany->pays_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->pays_code))."\n"; if ($targetcompany->pays_code && $targetcompany->pays_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->pays_code))."\n";
} }
// Intra VAT // Intra VAT
if ($targetcompany->tva_intra) $stringaddress.="\n".$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($targetcompany->tva_intra); if ($targetcompany->tva_intra) $stringaddress.="\n".$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($targetcompany->tva_intra);
// Professionnal Ids
if ($conf->global->MAIN_PROFID1_IN_ADDRESS) if ($conf->global->MAIN_PROFID1_IN_ADDRESS)
{ {
$tmp=$outputlangs->transcountrynoentities("ProfId1",$targetcompany->pays_code); $tmp=$outputlangs->transcountrynoentities("ProfId1",$targetcompany->pays_code);

View File

@ -754,37 +754,12 @@ class Livraison extends CommonObject
{ {
global $user,$langs,$conf; global $user,$langs,$conf;
// Charge tableau des id de societe socids
$socids = array();
$sql = "SELECT rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."societe";
$sql.= " WHERE client IN (1, 3)";
$sql.= " AND entity = ".$conf->entity;
$sql.= " LIMIT 10";
$resql = $this->db->query($sql);
if ($resql)
{
$num_socs = $this->db->num_rows($resql);
$i = 0;
while ($i < $num_socs)
{
$i++;
$row = $this->db->fetch_row($resql);
$socids[$i] = $row[0];
}
}
// Charge tableau des produits prodids // Charge tableau des produits prodids
$prodids = array(); $prodids = array();
$sql = "SELECT rowid"; $sql = "SELECT rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."product"; $sql.= " FROM ".MAIN_DB_PREFIX."product";
$sql.= " WHERE tosell = 1"; $sql.= " WHERE tosell = 1";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$conf->entity;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -802,8 +777,7 @@ class Livraison extends CommonObject
$this->id=0; $this->id=0;
$this->ref = 'SPECIMEN'; $this->ref = 'SPECIMEN';
$this->specimen=1; $this->specimen=1;
$socid = rand(1, $num_socs); $this->socid = 1;
$this->socid = $socids[$socid];
$this->date_delivery = time(); $this->date_delivery = time();
$this->note_public='SPECIMEN'; $this->note_public='SPECIMEN';