Compare commits
4 Commits
21fff9d4c0
...
ce18ebdb9a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce18ebdb9a | ||
|
|
905794c3c9 | ||
| bccfc0b7ed | |||
| 49ecf4b1ed |
@ -186,5 +186,7 @@ return [
|
||||
|
||||
|
||||
['name' => 'page#updateDevisLigneTrajet', 'url' => '/updateDevisLigneTrajet', 'verb' => 'POST'],
|
||||
|
||||
['name' => 'page#apiReloadFec', 'url' => '/apiReloadFec', 'verb' => 'POST' ],
|
||||
]
|
||||
];
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1357,7 +1357,7 @@ class PageController extends Controller
|
||||
{
|
||||
//$this->synchronize_facture();
|
||||
$result = $this->myDb->getFactures($this->idNextcloud);
|
||||
$this->refreshFEC();
|
||||
$this->reloadFec();
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -1368,7 +1368,7 @@ class PageController extends Controller
|
||||
public function getFacturesWithProduits()
|
||||
{
|
||||
$result = $this->myDb->getFacturesWithProduits();
|
||||
$this->refreshFEC();
|
||||
$this->reloadFec();
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -1642,7 +1642,7 @@ class PageController extends Controller
|
||||
public function insertFacture()
|
||||
{
|
||||
$result = $this->myDb->insertFacture($this->idNextcloud);
|
||||
$this->refreshFEC();
|
||||
$this->reloadFec();
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -1762,7 +1762,7 @@ class PageController extends Controller
|
||||
// $this->generer_document_comptable($facturecourant->date_paiement);
|
||||
}
|
||||
}
|
||||
$this->refreshFEC();
|
||||
$this->reloadFec();
|
||||
return $result;
|
||||
}
|
||||
return $this->myDb->gestion_update($table, $column, $data, $id, $this->idNextcloud);
|
||||
@ -1788,7 +1788,7 @@ class PageController extends Controller
|
||||
$factureIdsGenerated = $this->myDb->insertFactureForeEachDevisId($this->idNextcloud, $devisToFacture, $paymentDate);
|
||||
}
|
||||
$this->invoicePdfService->generateFacturePdfByFactureIds($factureIdsGenerated, $this->idNextcloud);
|
||||
$this->refreshFEC();
|
||||
$this->reloadFec();
|
||||
return $response;
|
||||
}
|
||||
|
||||
@ -1808,7 +1808,7 @@ class PageController extends Controller
|
||||
} else {
|
||||
$result = $this->myDb->gestion_delete($table, $id, $this->idNextcloud);
|
||||
}
|
||||
$this->refreshFEC();
|
||||
$this->reloadFec();
|
||||
return $result;
|
||||
}
|
||||
return $this->myDb->gestion_delete($table, $id, $this->idNextcloud);
|
||||
@ -2027,6 +2027,267 @@ class PageController extends Controller
|
||||
// //$file = $userFolder->get('myfile2.txt');
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function apiReloadFec() {
|
||||
$this->reloadFec();
|
||||
return new DataResponse("", 200, ['Content-Type' => 'application/json']);
|
||||
}
|
||||
|
||||
private function reloadFec(){
|
||||
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
|
||||
$clean_folder = html_entity_decode($current_config[0]->path).'/';
|
||||
|
||||
try {
|
||||
try {
|
||||
$data_factures = array();
|
||||
$factures = json_decode($this->myDb->getFacturesListWithDependencies());
|
||||
foreach ($factures as $key => $facture) {
|
||||
$factureIsSingle = $facture->facture_type == FactureTypeConstant::TYPE_SINGLE;
|
||||
$facture_temp = array(
|
||||
'num' => $facture->num,
|
||||
'client' => $facture->entreprise,
|
||||
'nom_client' => $facture->nom,
|
||||
'date' => $facture->date,
|
||||
'date_facture' => $facture->date_paiement,
|
||||
'defunt' => $facture->nom_defunt,
|
||||
'montant_htc' => 0,
|
||||
'tva' => $current_config[0]->tva_default,
|
||||
'montant_tva' => 0,
|
||||
'montant_ttc' => 0,
|
||||
);
|
||||
if($factureIsSingle){
|
||||
$produits = json_decode($this->getProduitsById($facture->id_devis));
|
||||
foreach ($produits as $key => $produit) {
|
||||
$htPrice = $produit->prix_unitaire;
|
||||
if($facture->fk_client_group_id != null || $facture->fk_client_group_id != 0){
|
||||
$price = $this->myDb->getProductPriceByClientGroupId($facture->fk_client_group_id,$produit->id);
|
||||
if($price != null){
|
||||
$htPrice = $price;
|
||||
}
|
||||
}
|
||||
$facture_temp['montant_htc'] += $htPrice * $produit->quantite;
|
||||
};
|
||||
$facture_temp['montant_tva'] = ($facture_temp['montant_htc'] * $facture_temp['tva'])/100;
|
||||
$facture_temp['montant_ttc'] = $facture_temp['montant_tva'] + $facture_temp['montant_htc'];
|
||||
}
|
||||
else{
|
||||
$devis = $this->myDb->getDevisByFkFactureId($facture->id);
|
||||
$factureGroupIsRelatedToAnyDevis = $devis != null;
|
||||
$mentionFilters = [
|
||||
DevisMentionConstant::FACTURED,
|
||||
DevisMentionConstant::FACTURED_FORMATTED
|
||||
];
|
||||
|
||||
|
||||
$isFactureGroupForSingleClient = $facture->facture_client_id != null && $facture->facture_client_id != 0;
|
||||
if($isFactureGroupForSingleClient){
|
||||
$facture_temp["client"] = $facture->facture_client_entreprise;
|
||||
$facture_temp["nom_client"] = $facture->facture_client_name;
|
||||
|
||||
if(!$factureGroupIsRelatedToAnyDevis ){
|
||||
$devisList = $this->myDb->getDevisByClientIdAndMonthYear(
|
||||
$facture->facture_client_id,
|
||||
$facture->facture_month,
|
||||
$facture->facture_year,
|
||||
$mentionFilters
|
||||
);
|
||||
}
|
||||
}
|
||||
else{
|
||||
$facture_temp["client"] = $facture->group_code_comptable ??'-';
|
||||
$facture_temp["nom_client"] = $facture->facture_group_name;
|
||||
|
||||
if(!$factureGroupIsRelatedToAnyDevis ){
|
||||
$devisList = $this->myDb->getDevisByClientGroupFacturationIdAndMonthYear(
|
||||
$facture->facture_client_group_facturation_id,
|
||||
$facture->facture_month,
|
||||
$facture->facture_year,
|
||||
[
|
||||
DevisMentionConstant::FACTURED,
|
||||
DevisMentionConstant::FACTURED_FORMATTED
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
if($factureGroupIsRelatedToAnyDevis){
|
||||
$devisList = $this->myDb->getDevisByClientIdByFactureId($facture->id, $mentionFilters );
|
||||
}
|
||||
|
||||
foreach($devisList as $currentDevis){
|
||||
$produits = json_decode($this->getProduitsById($currentDevis['id']));
|
||||
foreach ($produits as $key => $produit) {
|
||||
$htPrice = $produit->prix_unitaire;
|
||||
if($currentDevis["fk_client_group_id"] != null || $currentDevis["fk_client_group_id"] != 0){
|
||||
$price = $this->myDb->getProductPriceByClientGroupId($currentDevis["fk_client_group_id"],$produit->id);
|
||||
if($price != null){
|
||||
$htPrice = $price;
|
||||
}
|
||||
}
|
||||
$facture_temp['montant_htc'] += $htPrice * $produit->quantite;
|
||||
};
|
||||
}
|
||||
$facture_temp['montant_tva'] = ($facture_temp['montant_htc'] * $facture_temp['tva'])/100;
|
||||
$facture_temp['montant_ttc'] = $facture_temp['montant_tva'] + $facture_temp['montant_htc'];
|
||||
}
|
||||
|
||||
array_push($data_factures, $facture_temp);
|
||||
};
|
||||
$data_temp = array();
|
||||
foreach ($data_factures as $key => $facture) {
|
||||
$datesplit = explode('-', $facture['date_facture']);
|
||||
if($data_temp[strval($datesplit[0])]==NULL) {
|
||||
$data_temp[strval($datesplit[0])][strval($datesplit[1])] = array(0=>$facture);
|
||||
} else {
|
||||
if($data_temp[strval($datesplit[0])][strval($datesplit[1])]==NULL) {
|
||||
$data_temp[strval($datesplit[0])][strval($datesplit[1])] = array(0=>$facture);
|
||||
} else {
|
||||
array_push($data_temp[strval($datesplit[0])][strval($datesplit[1])], $facture);
|
||||
}
|
||||
}
|
||||
}
|
||||
$fec_headers_txt = [
|
||||
utf8_decode('JOURNALCODE'),
|
||||
utf8_decode('JOURNALLIB'),
|
||||
utf8_decode('ECRITURENUM'),
|
||||
utf8_decode('ECRITUREDATE'),
|
||||
utf8_decode('COMPTENUM'),
|
||||
utf8_decode('COMPTELIB'),
|
||||
utf8_decode('COMPAUXLIB'),
|
||||
utf8_decode('COMPAUXNUM'),
|
||||
utf8_decode('PIECEREF'),
|
||||
utf8_decode('PIECEDATE'),
|
||||
utf8_decode('ECRITURELIB'),
|
||||
utf8_decode('DEBIT'),
|
||||
utf8_decode('CREDIT'),
|
||||
utf8_decode('ECRITURELET'),
|
||||
utf8_decode('DATELET'),
|
||||
utf8_decode('VALIDDATE'),
|
||||
utf8_decode('MONTANTDEVISE'),
|
||||
utf8_decode('IDEVISE'),
|
||||
];
|
||||
//parcours annee
|
||||
foreach ($data_temp as $key_annee => $annee) {
|
||||
//parcours annee
|
||||
$_clean_folder = $clean_folder.'FEC/'.$key_annee.'/';
|
||||
try {
|
||||
$this->storage->newFolder($_clean_folder);
|
||||
} catch(\OCP\Files\NotPermittedException $e) { }
|
||||
foreach ($annee as $key_mois => $mois) {
|
||||
// Initialize FEC headers
|
||||
|
||||
$fec_temp_txt = implode(TAB1, $fec_headers_txt) . PHP_EOL . PHP_EOL;
|
||||
$fec_temp = implode(';', $fec_headers_txt) . "\n\n";
|
||||
|
||||
foreach ($mois as $key => $facture) {
|
||||
// Define FEC entry data
|
||||
$fec_entries = [
|
||||
[
|
||||
'journal' => 'VT',
|
||||
'journal_lib' => 'VENTES',
|
||||
'ecriturenum' => '',
|
||||
'date' => $facture['date_facture'],
|
||||
'compte' => $facture['client'],
|
||||
'libelle_compte' => $facture['client'],
|
||||
'compauxlib' => '',
|
||||
'compauxnum' => '',
|
||||
'piece' => $facture['num'],
|
||||
'piece_date' => '',
|
||||
'libelle_ecriture' => $facture['nom_client'],
|
||||
'debit' => $facture['montant_ttc'],
|
||||
'credit' => '0',
|
||||
'ecriture_lettrage' => '',
|
||||
'date_lettrage' => '',
|
||||
'valid_date' => '',
|
||||
'montant_devise' => '',
|
||||
'devise' => 'EUR',
|
||||
],
|
||||
[
|
||||
'journal' => 'VT',
|
||||
'journal_lib' => 'VENTES',
|
||||
'ecriturenum' => '',
|
||||
'date' => $facture['date_facture'],
|
||||
'compte' => '706000',
|
||||
'libelle_compte' => 'VENTES DE MARCHANDISES',
|
||||
'compauxlib' => '',
|
||||
'compauxnum' => '',
|
||||
'piece' => $facture['num'],
|
||||
'piece_date' => '',
|
||||
'libelle_ecriture' => $facture['client'],
|
||||
'debit' => '0',
|
||||
'credit' => $facture['montant_htc'],
|
||||
'ecriture_lettrage' => '',
|
||||
'date_lettrage' => '',
|
||||
'valid_date' => '',
|
||||
'montant_devise' => '',
|
||||
'devise' => 'EUR',
|
||||
],
|
||||
[
|
||||
'journal' => 'VT',
|
||||
'journal_lib' => 'VENTES',
|
||||
'ecriturenum' => '',
|
||||
'date' => $facture['date_facture'],
|
||||
'compte' => '445710',
|
||||
'compauxlib' => '',
|
||||
'compauxnum' => '',
|
||||
'libelle_compte' => '',
|
||||
'piece' => $facture['num'],
|
||||
'piece_date' => '',
|
||||
'libelle_ecriture' => $facture['client'],
|
||||
'debit' => '',
|
||||
'credit' => $facture['montant_tva'],
|
||||
'ecriture_lettrage' => '',
|
||||
'date_lettrage' => '',
|
||||
'valid_date' => '',
|
||||
'montant_devise' => '',
|
||||
'devise' => 'EUR',
|
||||
]
|
||||
];
|
||||
|
||||
// Generate FEC entries
|
||||
foreach ($fec_entries as $entry) {
|
||||
$fec_line_txt = [
|
||||
$entry['journal'], $entry['journal_lib'], $entry['ecriturenum'], $entry['date'],
|
||||
$entry['compte'], $entry['libelle_compte'],
|
||||
$entry['compauxlib'], $entry['compauxnum'],
|
||||
$entry['piece'], $entry['piece_date'],
|
||||
$entry['libelle_ecriture'], $entry['debit'],$entry['credit'],$entry['ecriture_lettrage'],
|
||||
$entry['date_lettrage'], $entry['valid_date'], $entry['montant_devise'], $entry['devise']
|
||||
];
|
||||
|
||||
$fec_line_csv = [
|
||||
$entry['journal'], $entry['journal_lib'], $entry['ecriturenum'], $entry['date'],
|
||||
$entry['compte'], $entry['libelle_compte'],
|
||||
$entry['compauxlib'], $entry['compauxnum'],
|
||||
$entry['piece'], $entry['piece_date'],
|
||||
$entry['libelle_ecriture'], $entry['debit'],$entry['credit'],$entry['ecriture_lettrage'],
|
||||
$entry['date_lettrage'], $entry['valid_date'], $entry['montant_devise'], $entry['devise']
|
||||
];
|
||||
|
||||
$fec_temp_txt .= implode(TAB1, $fec_line_txt) . PHP_EOL . PHP_EOL;
|
||||
$fec_temp .= implode(';', $fec_line_csv) . "\n\n";
|
||||
}
|
||||
}
|
||||
$ff = $_clean_folder.'FEC_'.$key_mois.'_'.$key_annee.'.csv';
|
||||
$this->storage->newFile($ff);
|
||||
$file = $this->storage->get($ff);
|
||||
$file->putContent($fec_temp);
|
||||
|
||||
$ff_txt = $_clean_folder.'FEC_'.$key_mois.'_'.$key_annee.'.txt';
|
||||
$this->storage->newFile($ff_txt);
|
||||
$file_txt = $this->storage->get($ff_txt);
|
||||
$file_txt->putContent($fec_temp_txt);
|
||||
// $file->putContent(implode(';', array('Jane Smith', 'janesmith@example.com', '555-5678')) . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
} catch(\OCP\Files\NotFoundException $e) { }
|
||||
|
||||
} catch(\OCP\Files\NotPermittedException $e) { }
|
||||
}
|
||||
|
||||
private function refreshFEC()
|
||||
{
|
||||
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user