function update_data($f) { reset_status_cantine(); $new_f = str_replace(".csv", "_FAAA.csv", $f); //echo ($new_f)."<br>"; $fr = fopen($f, 'r'); $fw = fopen($new_f, 'w'); $total = 0; $touteslettres = ""; while (!feof($fr)) { $l = fgets($fr); $ar_l = explode(";", $l); if (is_numeric($ar_l[0])) { //echo "processing line ".$l."<br />"; $cf = $ar_l[5] / 100; $debut = mysqldateformat($ar_l[6]); $fin = mysqldateformat($ar_l[7]); $days = (strtotime($fin) - strtotime($debut)) / 86400; $months = round($days / 30); $ar_l[8] = "DP"; $ar_l[9] = $months; $ar_l[10] = 1600 * $cf; $ar_l[11] = $months * 1600 * $cf; $ar_l[12] = 0; $ar_l[13] = $ar_l[11]; $ar_l[14] = 0; $ar_l[15] = 0; $ar_l[16] = $ar_l[11]; $total += $ar_l[16]; $touteslettres = chiffre_en_lettre($total); $l = join(";", $ar_l); fwrite($fw, $l); $cps = $ar_l[1]; if ($ar_l[5] == "100") { $status = 15; } else { $status = 16; } update_enfant($cps, $status, $fin); } else { if (substr($l, 0, 3) == ";;;") { //end $l = str_replace("Total;;", "Total;{$total};", $l); $l = str_replace("(en toutes lettres) :", "(en toutes lettres) : {$touteslettres}", $l); fwrite($fw, $l); } else { //echo "ignoring line ".$l."<br />"; fwrite($fw, $l); } } unset($ar_l); } fclose($fr); fclose($fw); output_file($new_f, substr($new_f, 4), "csv"); }
/** * Write the object to document file to disk * * @param Don $don Donation object * @param Translate $outputlangs Lang object for output language * @return int >0 if OK, <0 if KO */ function write_file($don, $outputlangs) { global $user, $conf, $langs, $mysoc; $now = dol_now(); $id = !is_object($don) ? $don : ''; if (!is_object($outputlangs)) { $outputlangs = $langs; } $outputlangs->load("main"); $outputlangs->load("dict"); $outputlangs->load("companies"); $outputlangs->load("bills"); $outputlangs->load("products"); $outputlangs->load("donations"); if (!empty($conf->don->dir_output)) { // Definition of the object don (for upward compatibility) if (!is_object($don)) { $don = new Don($this->db); $ret = $don->fetch($id); $id = $don->id; } // Definition of $dir and $file if (!empty($don->specimen)) { $dir = $conf->don->dir_output; $file = $dir . "/SPECIMEN.html"; } else { $donref = dol_sanitizeFileName($don->ref); $dir = $conf->don->dir_output . "/" . $donref; $file = $dir . "/" . $donref . ".html"; } if (!file_exists($dir)) { if (dol_mkdir($dir) < 0) { $this->error = $langs->trans("ErrorCanNotCreateDir", $dir); return -1; } } if (file_exists($dir)) { $formclass = new Form($this->db); // This is not the proper way to do it but $formclass->form_modes_reglement // prints the translation instead of returning it if ($don->modepaiementid) { $formclass->load_cache_types_paiements(); $paymentmode = $formclass->cache_types_paiements[$don->modepaiementid]['label']; } else { $paymentmode = ''; } if ($don->modepaiementid == 7) { $ModePaiement = '<td width="25%"><input type="checkbox"> Remise d\'espèces</td><td width="25%"><input type="checkbox" disabled="true" checked="checked"> Chèque</td><td width="50%"><input type="checkbox"> Virement, prélèvement, carte bancaire</td>'; } else { if ($don->modepaiementid == 4) { $ModePaiement = '<td width="25%"><input type="checkbox" checked="checked"> Remise d\'espèces</td><td width="25%"><input type="checkbox"> Chèque</td><td width="50%"><input type="checkbox"> Virement, prélèvement, carte bancaire</td>'; } else { if ($don->modepaiementid == 2 or $don->modepaiementid == 3 or $don->modepaiementid == 6) { $ModePaiement = '<td width="25%"><input type="checkbox"> Remise d\'espèces</td><td width="25%"><input type="checkbox"> Chèque</td><td width="50%"><input type="checkbox" checked="checked"> Virement, prélèvement, carte bancaire</td>'; } else { $ModePaiement = '<td width="25%"><input type="checkbox"> Remise d\'espèces</td><td width="25%"><input type="checkbox"> Chèque</td><td width="50%"><input type="checkbox"> Virement, prélèvement, carte bancaire</td>'; } } } if (empty($don->societe)) { $CodeDon = '<td width="33%"><input type="checkbox" disabled="true" checked="checked" > 200 du CGI</td><td width="33%"><input type="checkbox" disabled="true" > 238 bis du CGI</td><td width="33%"><input type="checkbox" disabled="true" > 885-0 V bis A du CGI</td>'; } else { $CodeDon = '<td width="33%"><input type="checkbox" disabled="true" > 200 du CGI</td><td width="33%"><input type="checkbox" disabled="true" checked="checked" > 238 bis du CGI</td><td width="33%"><input type="checkbox" disabled="true" > 885-0 V bis A du CGI</td>'; } // Define contents $donmodel = DOL_DOCUMENT_ROOT . "/core/modules/dons/html_cerfafr.html"; $form = implode('', file($donmodel)); $form = str_replace('__REF__', $don->id, $form); $form = str_replace('__DATE__', dol_print_date($don->date, 'day', false, $outputlangs), $form); //$form = str_replace('__IP__',$user->ip,$form); // TODO $user->ip not exist $form = str_replace('__AMOUNT__', $don->amount, $form); $form = str_replace('__AMOUNTLETTERS__', chiffre_en_lettre($don->amount), $form); $form = str_replace('__CURRENCY__', $outputlangs->transnoentitiesnoconv("Currency" . $conf->currency), $form); $form = str_replace('__CURRENCYCODE__', $conf->currency, $form); $form = str_replace('__MAIN_INFO_SOCIETE_NOM__', $mysoc->name, $form); $form = str_replace('__MAIN_INFO_SOCIETE_ADDRESS__', $mysoc->address, $form); $form = str_replace('__MAIN_INFO_SOCIETE_ZIP__', $mysoc->zip, $form); $form = str_replace('__MAIN_INFO_SOCIETE_TOWN__', $mysoc->town, $form); $form = str_replace('__MAIN_INFO_SOCIETE_OBJECT__', $mysoc->object, $form); $form = str_replace('__DONATOR_FIRSTNAME__', $don->firstname, $form); $form = str_replace('__DONATOR_LASTNAME__', $don->lastname, $form); $form = str_replace('__DONATOR_SOCIETE__', $don->societe, $form); $form = str_replace('__DONATOR_STATUT__', $don->statut, $form); $form = str_replace('__DONATOR_ADDRESS__', $don->address, $form); $form = str_replace('__DONATOR_ZIP__', $don->zip, $form); $form = str_replace('__DONATOR_TOWN__', $don->town, $form); $form = str_replace('__PAYMENTMODE_LIB__ ', $paymentmode, $form); $form = str_replace('__ModePaiement__', $ModePaiement, $form); $form = str_replace('__NOW__', dol_print_date($now, 'day', false, $outputlangs), $form); $form = str_replace('__DonationRef__', $outputlangs->trans("DonationRef"), $form); $form = str_replace('__DonationTitle__', $outputlangs->trans("DonationTitle"), $form); $form = str_replace('__DonationReceipt__', $outputlangs->trans("DonationReceipt"), $form); $form = str_replace('__DonationRecipient__', $outputlangs->trans("DonationRecipient"), $form); $form = str_replace('__DonationDatePayment__', $outputlangs->trans("DonationDatePayment"), $form); $form = str_replace('__PaymentMode__', $outputlangs->trans("PaymentMode"), $form); $form = str_replace('__CodeDon__', $CodeDon, $form); $form = str_replace('__Name__', $outputlangs->trans("Name"), $form); $form = str_replace('__Address__', $outputlangs->trans("Address"), $form); $form = str_replace('__Zip__', $outputlangs->trans("Zip"), $form); $form = str_replace('__Town__', $outputlangs->trans("Town"), $form); $form = str_replace('__Object__', $outputlangs->trans("Object"), $form); $form = str_replace('__Donor__', $outputlangs->trans("Donor"), $form); $form = str_replace('__Date__', $outputlangs->trans("Date"), $form); $form = str_replace('__Signature__', $outputlangs->trans("Signature"), $form); $form = str_replace('__Message__', $outputlangs->trans("Message"), $form); $form = str_replace('__IConfirmDonationReception__', $outputlangs->trans("IConfirmDonationReception"), $form); $form = str_replace('__DonationMessage__', $conf->global->DONATION_MESSAGE, $form); $frencharticle = ''; if (preg_match('/fr/i', $outputlangs->defaultlang)) { $frencharticle = '<font size="+1">Article 200, 238 bis et 885-0 V bis A du code général des impôts (CGI)</font>'; } $form = str_replace('__FrenchArticle__', $frencharticle, $form); $frencheligibility = ''; if (preg_match('/fr/i', $outputlangs->defaultlang)) { $frencheligibility = 'Le bénéficiaire certifie sur l\'honneur que les dons et versements qu\'il reçoit ouvrent droit à la réduction d\'impôt prévue à l\'article :'; } $form = str_replace('__FrenchEligibility__', $frencheligibility, $form); $art200 = ''; if (preg_match('/fr/i', $outputlangs->defaultlang)) { if ($conf->global->DONATION_ART200 >= 1) { $art200 = '<input type="checkbox" disabled="true" checked="checked" >200 du CGI'; } else { $art200 = '<input type="checkbox" disabled="true">200 du CGI'; } } $form = str_replace('__ARTICLE200__', $art200, $form); $art238 = ''; if (preg_match('/fr/i', $outputlangs->defaultlang)) { if ($conf->global->DONATION_ART238 >= 1) { $art238 = '<input type="checkbox" disabled="true" checked="checked" >238 bis du CGI'; } else { $art238 = '<input type="checkbox" disabled="true">238 bis du CGI'; } } $form = str_replace('__ARTICLE238__', $art238, $form); $art885 = ''; if (preg_match('/fr/i', $outputlangs->defaultlang)) { if ($conf->global->DONATION_ART885 >= 1) { $art885 = '<input type="checkbox" disabled="true" checked="checked" >885-0 V bis du CGI'; } else { $art885 = '<input type="checkbox" disabled="true">885-0 V bis du CGI'; } } $form = str_replace('__ARTICLE885__', $art885, $form); // Save file on disk dol_syslog("html_cerfafr::write_file {$file}"); $handle = fopen($file, "w"); fwrite($handle, $form); fclose($handle); if (!empty($conf->global->MAIN_UMASK)) { @chmod($file, octdec($conf->global->MAIN_UMASK)); } return 1; } else { $this->error = $langs->trans("ErrorCanNotCreateDir", $dir); return 0; } } else { $this->error = $langs->trans("ErrorConstantNotDefined", "DON_OUTPUTDIR"); return 0; } $this->error = $langs->trans("ErrorUnknown"); return 0; // Error by default }