<?php
namespace App\Controller\GestionComerciale;
use App\Entity\Adresses\Adresse;
use App\Entity\Articles\Article;
use App\Entity\Articles\ArticleCategorie;
use App\Entity\Articles\Categorie;
use App\Entity\Articles\ConditionAchat;
use App\Entity\Rangements\Caisse;
use App\Entity\Articles\ConditionnementAchat;
use App\Entity\Articles\ConditionVente;
use App\Entity\Clients\Client;
use App\Entity\FO\CompteBancaire;
use App\Entity\Fournisseurs\Fournisseur;
use App\Entity\GestionComerciale\Acompte;
use App\Entity\GestionComerciale\ArticleCommande;
use App\Entity\GestionComerciale\Commande;
use App\Entity\GestionComerciale\CommandeFournisseur;
use App\Entity\GestionComerciale\Fabrication;
use App\Entity\GestionComerciale\FabricationMultiple;
use App\Model\GestionCommerciale\TypeDocumentCommercial;
use App\Entity\Taxes\Taxe;
use App\Entity\Traductions\Traduction;
use App\Form\GestionComercialeBundle\CopiesLignesType;
use App\Service\Articles\ArticleService;
use App\Service\FO\DateService;
use App\Service\Fournisseurs\FournisseurService;
use App\Service\GestionComerciale\CommandeService;
use App\Service\GestionComerciale\FabricationService;
use App\Service\Utilisateur\ColonneTableauService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class ActionAjaxController extends AbstractController
{
/**
* @Route("/commande-article/interchanger/{commande}/{article}", name="dtc_article_est_interchangeable")
*/
public function articleEstInterchangeableAction(Request $request, Commande $commande, Article $article, EntityManagerInterface $em)
{
$rendu = true;
$typeBon = TypeDocumentCommercial::BP;
$bonPreparations = $em->getRepository(Commande::class)->findBy(["commande" => $commande, "typeDocumentCommercial" => $typeBon]);
$repo_article_commande = $em->getRepository(ArticleCommande::class);
foreach ($bonPreparations as $b) {
if ( ! is_object($b->getStatutCommande()) or (is_object($b->getStatutCommande()) and $b->getStatutCommande()->getOrdre() != 0)) {
$articleBon = $repo_article_commande->findBy(["commande" => $b, "article" => $article]);
foreach ($articleBon as $ab) {
$rendu = false;
}
}
}
return new JsonResponse(['rendu' => $rendu]);
}
/**
* @Route("/vente/commande/ajax/detail/{id}", name="dtc_commande_detail_ajax")
*/
public function detailCommandeAction(Request $request, Commande $commande)
{
$get = $request->query->all();
$mode = "";
if ( ! empty($get["mode"])) {
$mode = $get["mode"];
}
$rendu = $this->renderView('GestionComerciale/Commande/detail_datatable.html.twig', ['commande' => $commande, "mode" => $mode]);
return new JsonResponse(['rendu' => $rendu]);
}
/**
* @Route("/vente/ofm/ajax/detail/{id}", name="dtc_ofm_detail_ajax")
*/
public function detailOfmAction(Request $request, FabricationMultiple $ofm)
{
$rendu = $this->renderView('GestionComerciale/FabricationMultiple/detail_datatable.html.twig', ['ofm' => $ofm]);
return new JsonResponse(['rendu' => $rendu,]);
}
/**
* @Route("/vente/caisse/ajax/detail/{id}", name="dtc_caisse_detail_ajax")
*/
public function detailCaisseAction(Request $request, Caisse $caisse, EntityManagerInterface $em)
{
$repo_fabrication = $em->getRepository(Fabrication::class);
$fabrications = $repo_fabrication->findBy(["caisse"=>$caisse,'statutFabrication'=>11]);
$rendu = $this->renderView('Rangements/CaisseEmballer/detail_datatable.html.twig', ['caisse' => $caisse,'fabrications'=>$fabrications]);
return new JsonResponse(['rendu' => $rendu,]);
}
/**
* @Route("/vente/commande-fournisseur/ajax/detail/{id}", name="dtc_commande_fournisseur_detail_ajax")
*/
public function detailCommandeFournisseurAction(Request $request, CommandeFournisseur $commande)
{
$rendu = $this->renderView('GestionComerciale/CommandeFournisseur/detail_datatable.html.twig', ['commande' => $commande]);
return new JsonResponse(['rendu' => $rendu,]);
}
/**
* @Route("/commande-article/interchanger/{commande}/{article}", name="dtc_article_est_interchangeable")
* @Route("/commentaire/nouveau/", name="dtc_construire_ligne_commentaire_commande")
*/
public function construireLigneCommentaireCommandeAction(Request $request, EntityManagerInterface $em, ArticleService $serviceArticle, CommandeService $commandeService,
ColonneTableauService $serviceColonne
) {
$conn = $em->getConnection();
$conn->getConfiguration()->setSQLLogger(null);
$repo_article = $em->getRepository(Article::class);
$repo_commande = $em->getRepository(Commande::class);
$repo_article_commande = $em->getRepository(ArticleCommande::class);
$commandeId = $request->query->get('commande');
$article = $repo_article->find($this->getParameter('article_commentaire'));
$quantite = $request->query->get('quantite');
$client_id = $request->query->get('client');
$cible = $request->query->get('cible');
$type = '';
$a = [];
$a['quantiteDejaPreparee'] = 0;
$a['articleCommandeRepris'] = "";
$a['position'] = "";
$a['action'] = "insert";
$a['article'] = $article;
$a['libelle'] = $article->getLibelle();
$a['libelleSecondaire'] = $article->getLibelleSecondaire();
$a['quantite'] = "1";
$a['quantitePrepa'] = "1";
$a['fraisPort'] = "0";
$a['estCommentaire'] = $article->getEstCommentaire();
$a['commentaire'] = "";
$a['commentaireSuppl'] = "";
$a['commentairePrive'] = "";
$a['remise'] = 0;
$a['remiseSupplementaire'] = 0;
//$a['ecocontribution']= floatval($article->getEcocontribution());
$a['ecocontribution'] = 0;
$a['totalHt'] = $article->getPrixVente();
$a['totalHtV2'] = $article->getPrixVente();
$a['couleur'] = $serviceArticle->getCouleurEtatStock($article, $a['quantite']);
$commande = null;
if ($commandeId != '') {
$commande = $repo_commande->find($commandeId);
//$type = 'commande';
}
$a['position'] = 0;
if (is_object($commande)) {
$a['commande'] = $commande;
$a['position'] = count($commande->getArticleCommande());
} else {
$a['commande'] = null;
}
//sauvegarde auto
if (is_object($commande)) {
if (is_int($commande->getTypeDocumentCommercial()) && in_array($commande->getTypeDocumentCommercial(), [TypeDocumentCommercial::COMMANDE])) {
$type = 'commande';
}
//modification des donnees pour l'enregistrement
if (is_object($a['article'])) {
$a['article_id'] = $a['article']->getId();
}
if (is_object($a['commande'])) {
$a['commande_id'] = $a['commande']->getId();
}
$a['libelle_secondaire'] = $a['libelleSecondaire'];
$a['frais_port'] = $a['fraisPort'];
$a['ral_client'] = $a['quantite'];
//$a['est_commentaire'] = $a['estCommentaire'];
$a['commentaire_suppl'] = $a['commentaireSuppl'];
$a['commentaire_prive'] = $a['commentairePrive'];
$a['remise_supplementaire'] = $a['remiseSupplementaire'];
$a['total_ht'] = $a['totalHt'];
//$a['total_ht_v2'] = $a['totalHtV2'];
$a['quantite_deja_preparee'] = $a['quantiteDejaPreparee'];
$a['date'] = (new \Datetime)->format('Y-m-d H:i:s');
if (is_object($a['articleCommandeRepris'])) {
$a['article_commande_repris_id'] = $a['articleCommandeRepris']->getId();
}
unset($a['articleCommandeRepris']);
unset($a['transporteur']);
unset($a['article']);
unset($a['commande']);
unset($a['action']);
unset($a['libelleSecondaire']);
unset($a['fraisPort']);
unset($a['quantitePrepa']);
//unset($a['ralClient']);
unset($a['estCommentaire']);
unset($a['commentaireSuppl']);
unset($a['commentairePrive']);
unset($a['remiseSupplementaire']);
unset($a['totalHt']);
unset($a['totalHtV2']);
unset($a['couleur']);
unset($a['quantiteDejaPreparee']);
$conn->insert('commerciale__article_commande', $a);
//$a['id'] = $conn->lastInsertId();
$a = $repo_article_commande->find($conn->lastInsertId());
$commandeService->creerHistorique($commande, 'ajout-ligne', ['articleCommande' => $a]);
} else {
$a['id'] = 'tmp-'.time();
}
/*
{% set tabColonneUser = tabColonneUser|merge({'id': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'reference': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'libelle': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'quantite': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'quantitePrepa': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'quantiteDejaPrepa': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'quantiteCmde': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'prixHT': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'remise': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'prixHTCalc': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'totalHT': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'stock': 1}) %}
*/
if ($cible == "or") {
$colspan = 13;
$tabColonneUser = [];
$tabColonneUser["id"] = 1;
$tabColonneUser["reference"] = 1;
$tabColonneUser["libelle"] = 1;
$tabColonneUser["quantite"] = 1;
$tabColonneUser["quantitePrepa"] = 1;
$tabColonneUser["quantiteDejaPrepa"] = 1;
$tabColonneUser["quantiteCmde"] = 1;
$tabColonneUser["prixHT"] = 1;
$tabColonneUser["remise"] = 1;
$tabColonneUser["prixHTCalc"] = 1;
$tabColonneUser["totalHT"] = 1;
$tabColonneUser["stock"] = 1;
// TODO CHANGE THIS
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormOrdreRep";
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'id') == false) {
$colspan--;
$tabColonneUser["id"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'reference') == false) {
$colspan--;
$tabColonneUser["reference"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'libelle') == false) {
$colspan--;
$tabColonneUser["libelle"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'quantite') == false) {
$colspan--;
$tabColonneUser["quantite"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'quantitePrepa') == false) {
$colspan--;
$tabColonneUser["quantitePrepa"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'quantiteDejaPrepa') == false) {
$colspan--;
$tabColonneUser["quantiteDejaPrepa"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'quantiteCmde') == false) {
$colspan--;
$tabColonneUser["quantiteCmde"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'prixHT') == false) {
$colspan--;
$tabColonneUser["prixHT"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'remise') == false) {
$colspan--;
$tabColonneUser["remise"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'remise') == false) {
$colspan--;
$tabColonneUser["remise"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'prixHTCalc') == false) {
$colspan--;
$tabColonneUser["prixHTCalc"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'totalHT') == false) {
$colspan--;
$tabColonneUser["totalHT"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'stock') == false) {
$colspan--;
$tabColonneUser["stock"] = 0;
}
} else {
/*
$serviceColonne = $this->get('dtc.colonne.tableau');
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormCommande";
$colspan = 11;
$tabColonneUser = array();
$tabColonneUser["id"]=1;
$tabColonneUser["reference"]=1;
$tabColonneUser["libelle"]=1;
$tabColonneUser["quantite"]=1;
$tabColonneUser["prixHT"]=1;
$tabColonneUser["remise"]=1;
$tabColonneUser["remiseSuppl"]=1;
$tabColonneUser["montantHT"]=1;
$tabColonneUser["totalHT"]=1;
$tabColonneUser["pump"]=1;
$tabColonneUser["stock"]=1;
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'id') == false) {
$colspan--;
$tabColonneUser["id"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'reference') == false) {
$colspan--;
$tabColonneUser["reference"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'libelle') == false) {
$colspan--;
$tabColonneUser["libelle"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'quantite') == false) {
$colspan--;
$tabColonneUser["quantite"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'prixHT') == false) {
$colspan--;
$tabColonneUser["prixHT"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'remise') == false) {
$colspan--;
$tabColonneUser["remise"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'remiseSuppl') == false) {
$colspan--;
$tabColonneUser["remiseSuppl"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'montantHT') == false) {
$colspan--;
$tabColonneUser["montantHT"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'totalHT') == false) {
$colspan--;
$tabColonneUser["totalHT"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'pump') == false) {
$colspan--;
$tabColonneUser["pump"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'stock') == false) {
$colspan--;
$tabColonneUser["stock"]=0;
}
*/
// TODO change this
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormCommande";
if ($cible == "comptoir") {
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormComptoir";
}
if ($cible == "bp") {
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormBP";
}
if ($cible == "devis") {
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormDevis";
}
if ($cible == "") {
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormDevis";
}
$colonneUtilisateur2 = $serviceColonne->getColonneUtilisateur2($colonneUtilisateur);
$tabColonneUser = $colonneUtilisateur2['tabColonneUser'];
$colspan = $colonneUtilisateur2['colspan'];
}
$variables = ['a' => $a, 'boucle' => "0", 'numeroLigne' => "0", 'colspan' => $colspan, 'tabColonneUser' => $tabColonneUser, 'type' => $type];
if ($cible == "or") {
$rendu = $this->renderView('GestionComerciale/ArticleCommande/template_or_tr.html.twig', $variables);
} elseif ($cible == "regularisation") {
$rendu = $this->renderView('GestionComerciale/ArticleCommande/template_regulation_tr.html.twig', $variables);
} else {
$rendu = $this->renderView('GestionComerciale/ArticleCommande/template_tr.html.twig', $variables);
}
$commentairePonctuel = $article->getCommentairePonctuel();
if ($article->getArretGamme()) {
$commentairePonctuel .= "<div>Attention article en arrêt de gamme</div>";
}
return new JsonResponse(['rendu' => $rendu, 'id' => $article->getId(), 'commentairePonctuel' => $commentairePonctuel]
);
}
/**
* @Route("/commande-article/nouveau/{id}", name="dtc_construire_ligne_article_commande")
*/
public function construireLigneArticleCommandeAction(Request $request, Article $article, EntityManagerInterface $em, ColonneTableauService $serviceColonne,
ArticleService $serviceArticle, CommandeService $commandeService
) {
$enregAuto = false;
$conn = $em->getConnection();
$conn->getConfiguration()->setSQLLogger(null);
$quantite = $request->query->get('quantite');
$quantiteSurCommande = $request->query->get('quantiteSurCommande');
$client_id = $request->query->get('client');
$cible = $request->query->get('cible');
$commandeId = $request->query->get('commande');
$adresse = $request->query->get('adresse');
$articleImpression = $this->getParameter('article_impression');
if ($adresse != '') {
$adresse = $em->getRepository(Adresse::class)->find($adresse);
}
$type = '';
$repo_client = $em->getRepository(Client::class);
$repo_article = $em->getRepository(Article::class);
$repo_commande = $em->getRepository(Commande::class);
$repo_article_commande = $em->getRepository(ArticleCommande::class);
$consigne = "";
if ($cible == "or") {
// TODO CHANGE THIS
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormOrdreRep";
$colspan = 13;
$tabColonneUser = [];
$tabColonneUser["id"] = 1;
$tabColonneUser["reference"] = 1;
$tabColonneUser["libelle"] = 1;
$tabColonneUser["quantite"] = 1;
$tabColonneUser["quantitePrepa"] = 1;
$tabColonneUser["quantiteDejaPrepa"] = 1;
$tabColonneUser["quantiteCmde"] = 1;
$tabColonneUser["prixHT"] = 1;
$tabColonneUser["remise"] = 1;
$tabColonneUser["prixHTCalc"] = 1;
$tabColonneUser["totalHT"] = 1;
$tabColonneUser["dispo"] = 1;
$tabColonneUser["stock"] = 1;
$tabColonneUser["transporteur"] = 1;
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'id') == false) {
$colspan--;
$tabColonneUser["id"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'reference') == false) {
$colspan--;
$tabColonneUser["reference"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'libelle') == false) {
$colspan--;
$tabColonneUser["libelle"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'quantite') == false) {
$colspan--;
$tabColonneUser["quantite"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'quantitePrepa') == false) {
$colspan--;
$tabColonneUser["quantitePrepa"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'quantiteDejaPrepa') == false) {
$colspan--;
$tabColonneUser["quantiteDejaPrepa"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'quantiteCmde') == false) {
$colspan--;
$tabColonneUser["quantiteCmde"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'prixHT') == false) {
$colspan--;
$tabColonneUser["prixHT"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'remise') == false) {
$colspan--;
$tabColonneUser["remise"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'remise') == false) {
$colspan--;
$tabColonneUser["remise"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'prixHTCalc') == false) {
$colspan--;
$tabColonneUser["prixHTCalc"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'totalHT') == false) {
$colspan--;
$tabColonneUser["totalHT"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'dispo') == false) {
$colspan--;
$tabColonneUser["dispo"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'stock') == false) {
$colspan--;
$tabColonneUser["stock"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'transporteur') == false) {
$colspan--;
$tabColonneUser["transporteur"] = 0;
}
} else {
// TODO CHANGE THIS
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormCommande";
if ($cible == "comptoir") {
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormComptoir";
}
if ($cible == "bp") {
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormBP";
}
if ($cible == "devis") {
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormDevis";
}
if ($cible == "") {
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormDevis";
}
$colonneUtilisateur2 = $serviceColonne->getColonneUtilisateur2($colonneUtilisateur);
$tabColonneUser = $colonneUtilisateur2['tabColonneUser'];
$colspan = $colonneUtilisateur2['colspan'];
/*
$colspan = 11;
$tabColonneUser = array();
$tabColonneUser["id"]=1;
$tabColonneUser["reference"]=1;
$tabColonneUser["libelle"]=1;
$tabColonneUser["quantite"]=1;
$tabColonneUser["prixHT"]=1;
$tabColonneUser["remise"]=1;
$tabColonneUser["remiseSuppl"]=1;
$tabColonneUser["montantHT"]=1;
$tabColonneUser["totalHT"]=1;
$tabColonneUser["pump"]=1;
$tabColonneUser["dispo"]=1;
$tabColonneUser["stock"]=1;
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'id') == false) {
$colspan--;
$tabColonneUser["id"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'reference') == false) {
$colspan--;
$tabColonneUser["reference"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'libelle') == false) {
$colspan--;
$tabColonneUser["libelle"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'quantite') == false) {
$colspan--;
$tabColonneUser["quantite"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'prixHT') == false) {
$colspan--;
$tabColonneUser["prixHT"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'remise') == false) {
$colspan--;
$tabColonneUser["remise"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'remiseSuppl') == false) {
$colspan--;
$tabColonneUser["remiseSuppl"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'montantHT') == false) {
$colspan--;
$tabColonneUser["montantHT"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'totalHT') == false) {
$colspan--;
$tabColonneUser["totalHT"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'pump') == false) {
$colspan--;
$tabColonneUser["pump"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'dispo') == false) {
$colspan--;
$tabColonneUser["dispo"]=0;
}
if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'stock') == false) {
$colspan--;
$tabColonneUser["stock"]=0;
}
*
*/
/*
{% set tabColonneUser = tabColonneUser|merge({'id': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'reference': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'libelle': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'quantite': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'prixHT': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'remise': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'remiseSuppl': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'montantHT': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'totalHT': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'pump': 1}) %}
{% set tabColonneUser = tabColonneUser|merge({'stock': 1}) %}
*/
}
$rendu = '';
$commentairePonctuel = '';
$articlesTmp = [
[
'article' => $article,
'quantite' => $quantite,
],
];
$articlesAssocies = $article->getArticlesAssociesParent();
//$articlesAssocies = $em->getRepository('DTCArticlesBundle:ArticleAssocie')->findByParent($article);
if (count($articlesAssocies)) {
foreach ($articlesAssocies as $articleAssocie) {
$articlesTmp[] = [
'article' => $articleAssocie->getEnfant(),
'quantite' => $articleAssocie->getQuantite(),
];
}
}
$idArticleCommandeTmp = 'tmp-'.time();
$articleCommandeAssocie = null;
$countTmp = 0;
foreach ($articlesTmp as $articleTmp) {
$a = [];
/*
if($countTmp == 0){
$a['id'] = $idArticleCommandeTmp;
} else {
$a['articleCommandeAssocie']['id'] = $idArticleCommandeTmp;
}
$countTmp++;
*/
$article = $articleTmp['article'];
$quantite = $articleTmp['quantite'];
if ( ! empty($request->query->get('choix_matiere'))) {
if ($article->getId() == $articleImpression) {
}
$poidsImpression = 0;
$prixImpression = $request->query->get('prixImpression');
$designationImpression = $request->query->get('designation');
$poidsImpression = $request->query->get('poids');
$largeur_impression = $request->query->get('largeur_impression');
$longueur_impression = $request->query->get('longueur_impression');
$reference_impression = $request->query->get('reference_impression');
if ($longueur_impression == "") {
$longueur_impression = null;
} else {
$longueur_impression = $longueur_impression / 10;
}
if ($largeur_impression == "") {
$largeur_impression = null;
} else {
$largeur_impression = $largeur_impression / 10;
}
// $prixImpression = str_replace(".",",",$prixImpression);
$descriptionImpression = $designationImpression;
$designationImpression = strtok($designationImpression, "\n");
if ($poidsImpression != '' && is_numeric($quantite) && $quantite > 0) {
$poidsImpression = round($poidsImpression / $quantite, 2);
}
$prixImpression = round($prixImpression, 2);
}
if ( ! empty($request->query->get('choix_matiere'))) {
//echo "ABCDEFG";
$poidsImpression = 0;
//$prixImpression = $request->query->get('prixImpression');
$prixImpression = $request->query->get('prix_impression');
$designationImpression = $request->query->get('designation');
//$poidsImpression = $request->query->get('poids');
$poidsImpression = $request->query->get('poids_impression');
$largeur_impression = $request->query->get('largeur_impression');
$longueur_impression = $request->query->get('longueur_impression');
$reference_impression = $request->query->get('reference_impression');
if ($longueur_impression == "") {
$longueur_impression = null;
} else {
$longueur_impression = $longueur_impression / 10;
}
if ($largeur_impression == "") {
$largeur_impression = null;
} else {
$largeur_impression = $largeur_impression / 10;
}
// $prixImpression = str_replace(".",",",$prixImpression);
$descriptionImpression = $designationImpression;
$designationImpression = strtok($designationImpression, "\n");
if ($poidsImpression != '' && is_numeric($quantite) && $quantite > 0) {
$poidsImpression = round($poidsImpression / $quantite, 2);
}
$prixImpression = round($prixImpression, 2);
if ($article->getId() == $articleImpression) {
/*
$poidsImpression = 0;
$prixImpression = $request->query->get('prixImpression');
$designationImpression = $request->query->get('designation');
$poidsImpression = $request->query->get('poids');
$largeur_impression = $request->query->get('largeur_impression');
$longueur_impression = $request->query->get('longueur_impression');
$reference_impression = $request->query->get('reference_impression');
if($longueur_impression=="") $longueur_impression = NULL;
else $longueur_impression = $longueur_impression/10;
if($largeur_impression=="") $largeur_impression = NULL;
else $largeur_impression = $largeur_impression/10;
// $prixImpression = str_replace(".",",",$prixImpression);
$descriptionImpression = $designationImpression;
$designationImpression = strtok($designationImpression, "\n");
if ($poidsImpression != '' && is_numeric($quantite) && $quantite > 0) $poidsImpression = round($poidsImpression/$quantite,2);
$prixImpression = round($prixImpression,2);
*/
$dateC = new \Datetime();
$tableau_donnee = [];
$tableau_donnee["date"] = $dateC->format("Y-m-d H:i:s");
if ($reference_impression != "") {
$tableau_donnee["reference"] = $reference_impression."-".time();
} else {
$tableau_donnee["reference"] = $article->getReference()."-".time();
}
$tableau_donnee["ral_fournisseur"] = "0";
$tableau_donnee["parent_id"] = $article->getId();
$tableau_donnee["libelle"] = $designationImpression;
$tableau_donnee["reference_client"] = $article->getReferenceClient();
$tableau_donnee["reference_fournisseur"] = $article->getReferenceFournisseur();
$tableau_donnee["prix_base"] = $prixImpression;
if ($article->getDateMaj() != "") {
$tableau_donnee["date_maj"] = $article->getDateMaj()->format("Y-m-d H:i:s");
}
if ($article->getDateMajPrix() != "") {
$tableau_donnee["date_maj_prix"] = $article->getDateMajPrix()->format("Y-m-d H:i:s");
}
if ($article->getDateSuppression() != "") {
$tableau_donnee["date_supression"] = $article->getDateSuppression()->format("Y-m-d H:i:s");
}
if (is_object($article->getMarque())) {
$tableau_donnee["marque_id"] = $article->getMarque()->getId();
}
$tableau_donnee["description"] = $descriptionImpression;
$tableau_donnee["description_courte"] = $article->getDescriptionCourte();
$tableau_donnee["stock"] = "0";
if ($article->getStatut() === true) {
$tableau_donnee["statut"] = 1;
} else {
$tableau_donnee["statut"] = 0;
}
$tableau_donnee["largeur"] = $largeur_impression;;
$tableau_donnee["profondeur"] = $longueur_impression;
$tableau_donnee["hauteur"] = $article->getHauteur();
$tableau_donnee["poids"] = $poidsImpression;
if ($article->getAConsigner() === true) {
$tableau_donnee["a_consigner"] = 1;
} else {
$tableau_donnee["a_consigner"] = 0;
}
if ($article->getStockAuto()) {
$tableau_donnee["stock_auto"] = 1;
} else {
$tableau_donnee["stock_auto"] = 0;
}
if ($article->getArretGamme()) {
$tableau_donnee["arret_gamme"] = "1";
} else {
$tableau_donnee["arret_gamme"] = "0";
}
if (is_object($article->getUtilisateur())) {
$tableau_donnee["utilisateur_id"] = $article->getUtilisateur()->getId();
}
if (is_object($article->getRegleTaxe())) {
$tableau_donnee["regle_taxe_id"] = $article->getRegleTaxe()->getId();
}
$tableau_donnee["remise_max"] = $article->getRemiseMax();
$tableau_donnee["type_remise_max"] = $article->getTypeRemiseMax();
$tableau_donnee["seuil_commande_f_mini"] = $article->getSeuilMiniCommandeFournisseur();
$tableau_donnee["seuil_commande_f_maxi"] = $article->getSeuilMaxiCommandeFournisseur();
if (is_object($article->getNiveauUn())) {
$tableau_donnee["niveau_un_id"] = $article->getNiveauUn()->getId();
}
if (is_object($article->getNiveauDeux())) {
$tableau_donnee["niveau_deux_id"] = $article->getNiveauDeux()->getId();
}
if (is_object($article->getNiveauTrois())) {
$tableau_donnee["niveau_trois_id"] = $article->getNiveauTrois()->getId();
}
if (is_object($article->getNiveauQuatre())) {
$tableau_donnee["niveau_quatre_id"] = $article->getNiveauQuatre()->getId();
}
$tableau_donnee["pump"] = $article->getCpump();
$tableau_donnee["commentaire"] = $article->getCommentairePonctuel();
if ($article->getVirtuel() === true) {
$tableau_donnee["virtuel"] = 1;
} else {
$tableau_donnee["virtuel"] = 0;
}
//$tableau_donnee["prix_vente"]=$article->getLibelle();
$tableau_donnee["prix_vente"] = $prixImpression;
$tableau_donnee["taux_marge"] = $article->getTauxMarge();
$tableau_donnee["marge"] = $article->getMarge();
$tableau_donnee["marge_reelle"] = $article->getMargeReelle();
$tableau_donnee["ecotaxe"] = $article->getEcotaxe();
$tableau_donnee["conditionnement"] = $article->getConditionnement();
$tableau_donnee["stock_reserve"] = $article->getStockReserve();
if (is_object($article->getFournisseurDefaut())) {
$tableau_donnee["fournisseur_defaut_id"] = $article->getFournisseurDefaut()->getId();
}
$tableau_donnee["ral_fournisseur"] = "0";
$tableau_donnee["id_import"] = "";
$tableau_donnee["donnees_import"] = "";
if ($article->getMajPrix()) {
$tableau_donnee["maj_prix"] = 1;
} else {
$tableau_donnee["maj_prix"] = 0;
}
$tableau_donnee["unite_mesure_id"] = 6;
if ($article->getAfficherComposantPdfInterne() === true) {
$tableau_donnee["afficher_composant_pdf_interne"] = 1;
} else {
$tableau_donnee["afficher_composant_pdf_interne"] = 0;
}
if ($article->getAfficherComposantPdfExterne() === true) {
$tableau_donnee["afficher_composant_pdf_externe"] = 1;
} else {
$tableau_donnee["afficher_composant_pdf_externe"] = 0;
}
if (is_object($article->getCategorieRemiseArticle())) {
$tableau_donnee["categorie_remise_article_id"] = $article->getCategorieRemiseArticle()->getId();
}
if ($article->getTemporaire()) {
$tableau_donnee["temporaire"] = 1;
} else {
$tableau_donnee["temporaire"] = null;
}
$tableau_donnee["libelle_secondaire"] = $article->getLibelleSecondaire();
$tableau_donnee["a_commander"] = "1";
$tableau_donnee["a_fabriquer"] = "0";
$tableau_donnee["quantite_conseillee_mini"] = $article->getQuantiteConseilleeMini();
$tableau_donnee["quantite_conseillee"] = $article->getQuantiteConseillee();
$tableau_donnee["quantite_conseillee_maxi"] = $article->getQuantiteConseilleeMaxi();
$tableau_donnee["archive"] = "0";
//$tableau_donnee["archive"]=$article->getArchive();
$tableau_donnee["coefficient_px_base_px_vente"] = $article->getCoefficientPrixBaseVente();
$tableau_donnee["nom_web"] = $article->getNomWeb();
$tableau_donnee["reference_web"] = $article->getReferenceWeb();
$tableau_donnee["reference_fournisseur_web"] = $article->getReferenceFournisseurWeb();
$tableau_donnee["description_web"] = $article->getDescriptionWeb();
$tableau_donnee["resume_web"] = $article->getResumeWeb();
$tableau_donnee["frais_ports_texte_web"] = $article->getFraisPortsTexteWeb();
$tableau_donnee["message_qd_en_stock"] = $article->getMessageQdEnStockWeb();
if (is_object($article->getArticleEnconsigne())) {
$tableau_donnee["article_enconsigne_id"] = $article->getArticleEnconsigne()->getId();
}
$tableau_donnee["reference_appel_1"] = null;
$tableau_donnee["reference_appel_2"] = null;
$tableau_donnee["reference_appel_3"] = null;
$tableau_donnee["reference_appel_4"] = null;
$tableau_donnee["reference_appel_5"] = null;
$tableau_donnee["reference_appel_6"] = null;
$tableau_donnee["reference_appel_7"] = null;
$tableau_donnee["reference_appel_8"] = null;
$tableau_donnee["reference_appel_9"] = null;
$tableau_donnee["reference_appel_10"] = null;
$tableau_donnee["reference_appel_11"] = str_replace([' ', '-', '.'], '', $tableau_donnee["reference"]);
if ($article->getMainOeuvre()) {
$tableau_donnee["main_oeuvre"] = "1";
} else {
$tableau_donnee["main_oeuvre"] = "0";
}
//$tableau_donnee["main_oeuvre"]=$article->getMainOeuvre();
$tableau_donnee["stock_reserve_fabrication"] = $article->getStockReserveFabrication();
if (is_object($article->getType())) {
$tableau_donnee["type_id"] = $article->getType()->getId();
}
if (is_object($article->getFamilleCompta())) {
$tableau_donnee["famille_compta_id"] = $article->getFamilleCompta()->getId();
}
if ($article->getPrestation() === true) {
$tableau_donnee["prestation"] = 1;
} else {
$tableau_donnee["prestation"] = 0;
}
if ($article->getNonStocke()) {
$tableau_donnee["non_stocke"] = "1";
} else {
$tableau_donnee["non_stocke"] = "0";
}
//$tableau_donnee["non_stocke"]=$article->getNonStocke();
if ($article->getNonCommandable() === true) {
$tableau_donnee["non_commandable"] = 1;
} else {
$tableau_donnee["non_commandable"] = 0;
}
if (is_object($article->getParent())) {
$tableau_donnee["parent_id"] = $article->getParent()->getId();
}
if ($article->getDivers()) {
$tableau_donnee["divers"] = 1;
} else {
$tableau_donnee["divers"] = 0;
}
if ($article->getMouvemente()) {
$tableau_donnee["mouvemente"] = "1";
} else {
$tableau_donnee["mouvemente"] = "0";
}
//$tableau_donnee["mouvemente"]=$article->getMouvemente();
if ($article->getNumSerieObligatoire() === true) {
$tableau_donnee["num_serie_obligatoire"] = 1;
} else {
$tableau_donnee["num_serie_obligatoire"] = 0;
}
if (is_object($article->getArticleRemplacement())) {
$tableau_donnee["article_remplacement_id"] = $article->getArticleRemplacement()->getId();
}
if ($article->getMajPoids()) {
$tableau_donnee["maj_poids"] = 1;
} else {
$tableau_donnee["maj_poids"] = 0;
}
if ($article->getMajPrixBase()) {
$tableau_donnee["maj_prix_base"] = 1;
} else {
$tableau_donnee["maj_prix_base"] = 0;
}
if ($article->getEstCommentaire()) {
$tableau_donnee["est_commentaire"] = 1;
} else {
$tableau_donnee["est_commentaire"] = 0;
}
$tableau_donnee["cond_achat"] = $article->getConditionnementAchat();
$tableau_donnee["seuil_critique"] = $article->getSeuilCritique();
$conn->insert('article__article', $tableau_donnee);
$idNouveauArticle = $conn->lastInsertId();
$article = $repo_article->find($idNouveauArticle);
} else {
//mise à jour des données impression
$descriptionImpression = $request->query->get('designation');
$tableau_donnee["libelle"] = $designationImpression;
$designationImpression = strtok($designationImpression, "\n");
$tableau_donnee["description"] = $descriptionImpression;
$tableau_donnee["reference"] = $request->query->get('reference_impression')."-".time();
$prixImpression = $request->query->get('prix_impression');
$tableau_donnee["prix_base"] = $prixImpression;
$tableau_donnee["prix_vente"] = $prixImpression;
$tableau_donnee["largeur"] = $request->query->get('largeur');
$tableau_donnee["hauteur"] = $request->query->get('hauteur');
$tableau_donnee["poids"] = $request->query->get('poids_impression');
$conn->update('article__article', $tableau_donnee, ['id' => $article->getId()]);
$em->refresh($article);
if ( ! empty($request->query->get('articleCommande'))) {
$a['id'] = $request->query->get('articleCommande');
}
}
//maj des composants de l'article
//suppression des composants
$req = $conn->prepare('DELETE FROM article__article_composant WHERE article_compose_id = :article');
$req->executeQuery(['article' => $article->getId()]);
//ajouter les composants
$tableau_donnee = [];
$composantsRef = [];
if ( ! empty($request->query->get('choix_matiere'))) {
$composantsRef[] = $request->query->get('choix_matiere');
}
if ( ! empty($request->query->get('choix_finition'))) {
$composantsRef[] = $request->query->get('choix_finition');
}
$articlesCategorie = $em->getRepository(ArticleCategorie::class)->findBy(['categorie' => $this->getParameter('categorie_options')]);
if (count($articlesCategorie)) {
foreach ($articlesCategorie as $articleCategorie) {
if ( ! empty($request->query->get($articleCategorie->getArticle()->getReference()))) {
$composantsRef[$articleCategorie->getArticle()->getReference()] = $request->query->get($articleCategorie->getArticle()->getReference());
}
}
}
$categories = $em->getRepository(Categorie::class)->findBy(['categorieParent' => $this->getParameter('categorie_options')]);
if (count($categories)) {
foreach ($categories as $categorie) {
//$articlesCategorie = $em->getRepository('DTCArticlesBundle:ArticleCategorie')->findBy(array('categorie'=>$categorie));
if ( ! empty($request->query->get($categorie->getReference()))) {
$composantsRef[$categorie->getReference()] = $request->query->get($categorie->getReference());
}
}
}
if (count($composantsRef)) {
foreach ($composantsRef as $composantRef) {
$composant = $repo_article->findOneBy(['reference' => $composantRef]);
if (is_object($composant)) {
$conn->insert(
'article__article_composant',
['article_compose_id' => $article->getId(), 'article_id' => $composant->getId(), 'date' => (new \Datetime)->format('Y-m-d H:i:s')]
);
}
}
}
} elseif ($article->getId() == $articleImpression) {
//echo "ABCDEFG";
$poidsImpression = 0;
$prixImpression = $request->query->get('prixImpression');
$designationImpression = $request->query->get('designation');
$poidsImpression = $request->query->get('poids');
$largeur_impression = $request->query->get('largeur_impression');
$longueur_impression = $request->query->get('longueur_impression');
$reference_impression = $request->query->get('reference_impression');
if ($longueur_impression == "") {
$longueur_impression = null;
} else {
$longueur_impression = $longueur_impression / 10;
}
if ($largeur_impression == "") {
$largeur_impression = null;
} else {
$largeur_impression = $largeur_impression / 10;
}
// $prixImpression = str_replace(".",",",$prixImpression);
$descriptionImpression = $designationImpression;
$designationImpression = strtok($designationImpression, "\n");
if ($poidsImpression != '' && is_numeric($quantite) && $quantite > 0) {
$poidsImpression = round($poidsImpression / $quantite, 2);
}
$prixImpression = round($prixImpression, 2);
$dateC = new \Datetime();
$conn = $em->getConnection();
$conn->getConfiguration()->setSQLLogger(null);
$tableau_donnee = [];
$tableau_donnee["date"] = $dateC->format("Y-m-d H:i:s");
if ($reference_impression != "") {
$tableau_donnee["reference"] = $reference_impression."-".time();
} else {
$tableau_donnee["reference"] = $article->getReference()."-".time();
}
$tableau_donnee["ral_fournisseur"] = "0";
$tableau_donnee["parent_id"] = $article->getId();
$tableau_donnee["libelle"] = $designationImpression;
$tableau_donnee["reference_client"] = $article->getReferenceClient();
$tableau_donnee["reference_fournisseur"] = $article->getReferenceFournisseur();
$tableau_donnee["prix_base"] = $prixImpression;
if ($article->getDateMaj() != "") {
$tableau_donnee["date_maj"] = $article->getDateMaj()->format("Y-m-d H:i:s");
}
if ($article->getDateMajPrix() != "") {
$tableau_donnee["date_maj_prix"] = $article->getDateMajPrix()->format("Y-m-d H:i:s");
}
if ($article->getDateSuppression() != "") {
$tableau_donnee["date_supression"] = $article->getDateSuppression()->format("Y-m-d H:i:s");
}
if (is_object($article->getMarque())) {
$tableau_donnee["marque_id"] = $article->getMarque()->getId();
}
$tableau_donnee["description"] = $descriptionImpression;
$tableau_donnee["description_courte"] = $article->getDescriptionCourte();
$tableau_donnee["stock"] = "0";
if ($article->getStatut() === true) {
$tableau_donnee["statut"] = 1;
} else {
$tableau_donnee["statut"] = 0;
}
$tableau_donnee["largeur"] = $largeur_impression;;
$tableau_donnee["profondeur"] = $longueur_impression;
$tableau_donnee["hauteur"] = $article->getHauteur();
$tableau_donnee["poids"] = $poidsImpression;
if ($article->getAConsigner() === true) {
$tableau_donnee["a_consigner"] = 1;
} else {
$tableau_donnee["a_consigner"] = 0;
}
if ($article->getStockAuto()) {
$tableau_donnee["stock_auto"] = 1;
} else {
$tableau_donnee["stock_auto"] = 0;
}
if ($article->getArretGamme()) {
$tableau_donnee["arret_gamme"] = "1";
} else {
$tableau_donnee["arret_gamme"] = "0";
}
if (is_object($article->getUtilisateur())) {
$tableau_donnee["utilisateur_id"] = $article->getUtilisateur()->getId();
}
if (is_object($article->getRegleTaxe())) {
$tableau_donnee["regle_taxe_id"] = $article->getRegleTaxe()->getId();
}
$tableau_donnee["remise_max"] = $article->getRemiseMax();
$tableau_donnee["type_remise_max"] = $article->getTypeRemiseMax();
$tableau_donnee["seuil_commande_f_mini"] = $article->getSeuilMiniCommandeFournisseur();
$tableau_donnee["seuil_commande_f_maxi"] = $article->getSeuilMaxiCommandeFournisseur();
if (is_object($article->getNiveauUn())) {
$tableau_donnee["niveau_un_id"] = $article->getNiveauUn()->getId();
}
if (is_object($article->getNiveauDeux())) {
$tableau_donnee["niveau_deux_id"] = $article->getNiveauDeux()->getId();
}
if (is_object($article->getNiveauTrois())) {
$tableau_donnee["niveau_trois_id"] = $article->getNiveauTrois()->getId();
}
if (is_object($article->getNiveauQuatre())) {
$tableau_donnee["niveau_quatre_id"] = $article->getNiveauQuatre()->getId();
}
$tableau_donnee["pump"] = $article->getCpump();
$tableau_donnee["commentaire"] = $article->getCommentairePonctuel();
if ($article->getVirtuel() === true) {
$tableau_donnee["virtuel"] = 1;
} else {
$tableau_donnee["virtuel"] = 0;
}
//$tableau_donnee["prix_vente"]=$article->getLibelle();
$tableau_donnee["prix_vente"] = $prixImpression;
$tableau_donnee["taux_marge"] = $article->getTauxMarge();
$tableau_donnee["marge"] = $article->getMarge();
$tableau_donnee["marge_reelle"] = $article->getMargeReelle();
$tableau_donnee["ecotaxe"] = $article->getEcotaxe();
$tableau_donnee["conditionnement"] = $article->getConditionnement();
$tableau_donnee["stock_reserve"] = $article->getStockReserve();
if (is_object($article->getFournisseurDefaut())) {
$tableau_donnee["fournisseur_defaut_id"] = $article->getFournisseurDefaut()->getId();
}
$tableau_donnee["ral_fournisseur"] = "0";
$tableau_donnee["id_import"] = "";
$tableau_donnee["donnees_import"] = "";
if ($article->getMajPrix()) {
$tableau_donnee["maj_prix"] = 1;
} else {
$tableau_donnee["maj_prix"] = 0;
}
$tableau_donnee["unite_mesure_id"] = 6;
if ($article->getAfficherComposantPdfInterne() === true) {
$tableau_donnee["afficher_composant_pdf_interne"] = 1;
} else {
$tableau_donnee["afficher_composant_pdf_interne"] = 0;
}
if ($article->getAfficherComposantPdfExterne() === true) {
$tableau_donnee["afficher_composant_pdf_externe"] = 1;
} else {
$tableau_donnee["afficher_composant_pdf_externe"] = 0;
}
if (is_object($article->getCategorieRemiseArticle())) {
$tableau_donnee["categorie_remise_article_id"] = $article->getCategorieRemiseArticle()->getId();
}
if ($article->getTemporaire()) {
$tableau_donnee["temporaire"] = 1;
} else {
$tableau_donnee["temporaire"] = null;
}
$tableau_donnee["libelle_secondaire"] = $article->getLibelleSecondaire();
$tableau_donnee["a_commander"] = "1";
$tableau_donnee["a_fabriquer"] = "0";
$tableau_donnee["quantite_conseillee_mini"] = $article->getQuantiteConseilleeMini();
$tableau_donnee["quantite_conseillee"] = $article->getQuantiteConseillee();
$tableau_donnee["quantite_conseillee_maxi"] = $article->getQuantiteConseilleeMaxi();
$tableau_donnee["archive"] = "0";
//$tableau_donnee["archive"]=$article->getArchive();
$tableau_donnee["coefficient_px_base_px_vente"] = $article->getCoefficientPrixBaseVente();
$tableau_donnee["nom_web"] = $article->getNomWeb();
$tableau_donnee["reference_web"] = $article->getReferenceWeb();
$tableau_donnee["reference_fournisseur_web"] = $article->getReferenceFournisseurWeb();
$tableau_donnee["description_web"] = $article->getDescriptionWeb();
$tableau_donnee["resume_web"] = $article->getResumeWeb();
$tableau_donnee["frais_ports_texte_web"] = $article->getFraisPortsTexteWeb();
$tableau_donnee["message_qd_en_stock"] = $article->getMessageQdEnStockWeb();
if (is_object($article->getArticleEnconsigne())) {
$tableau_donnee["article_enconsigne_id"] = $article->getArticleEnconsigne()->getId();
}
$tableau_donnee["reference_appel_1"] = null;
$tableau_donnee["reference_appel_2"] = null;
$tableau_donnee["reference_appel_3"] = null;
$tableau_donnee["reference_appel_4"] = null;
$tableau_donnee["reference_appel_5"] = null;
$tableau_donnee["reference_appel_6"] = null;
$tableau_donnee["reference_appel_7"] = null;
$tableau_donnee["reference_appel_8"] = null;
$tableau_donnee["reference_appel_9"] = null;
$tableau_donnee["reference_appel_10"] = null;
$tableau_donnee["reference_appel_11"] = str_replace([' ', '-', '.'], '', $tableau_donnee["reference"]);
if ($article->getMainOeuvre()) {
$tableau_donnee["main_oeuvre"] = "1";
} else {
$tableau_donnee["main_oeuvre"] = "0";
}
//$tableau_donnee["main_oeuvre"]=$article->getMainOeuvre();
$tableau_donnee["stock_reserve_fabrication"] = $article->getStockReserveFabrication();
if (is_object($article->getType())) {
$tableau_donnee["type_id"] = $article->getType()->getId();
}
if (is_object($article->getFamilleCompta())) {
$tableau_donnee["famille_compta_id"] = $article->getFamilleCompta()->getId();
}
if ($article->getPrestation() === true) {
$tableau_donnee["prestation"] = 1;
} else {
$tableau_donnee["prestation"] = 0;
}
if ($article->getNonStocke()) {
$tableau_donnee["non_stocke"] = "1";
} else {
$tableau_donnee["non_stocke"] = "0";
}
//$tableau_donnee["non_stocke"]=$article->getNonStocke();
if ($article->getNonCommandable() === true) {
$tableau_donnee["non_commandable"] = 1;
} else {
$tableau_donnee["non_commandable"] = 0;
}
if (is_object($article->getParent())) {
$tableau_donnee["parent_id"] = $article->getParent()->getId();
}
if ($article->getDivers()) {
$tableau_donnee["divers"] = 1;
} else {
$tableau_donnee["divers"] = 0;
}
if ($article->getMouvemente()) {
$tableau_donnee["mouvemente"] = "1";
} else {
$tableau_donnee["mouvemente"] = "0";
}
//$tableau_donnee["mouvemente"]=$article->getMouvemente();
if ($article->getNumSerieObligatoire() === true) {
$tableau_donnee["num_serie_obligatoire"] = 1;
} else {
$tableau_donnee["num_serie_obligatoire"] = 0;
}
if (is_object($article->getArticleRemplacement())) {
$tableau_donnee["article_remplacement_id"] = $article->getArticleRemplacement()->getId();
}
if ($article->getMajPoids()) {
$tableau_donnee["maj_poids"] = 1;
} else {
$tableau_donnee["maj_poids"] = 0;
}
if ($article->getMajPrixBase()) {
$tableau_donnee["maj_prix_base"] = 1;
} else {
$tableau_donnee["maj_prix_base"] = 0;
}
if ($article->getEstCommentaire()) {
$tableau_donnee["est_commentaire"] = 1;
} else {
$tableau_donnee["est_commentaire"] = 0;
}
$tableau_donnee["cond_achat"] = $article->getConditionnementAchat();
$tableau_donnee["seuil_critique"] = $article->getSeuilCritique();
$conn->insert('article__article', $tableau_donnee);
$idNouveauArticle = $conn->lastInsertId();
$article = $repo_article->find($idNouveauArticle);
} elseif ($article->getDiversComposes() == 1) {
$dateC = new \Datetime();
$conn = $em->getConnection();
$conn->getConfiguration()->setSQLLogger(null);
$tableau_donnee = [];
$tableau_donnee["divers_composes"] = 1;
$tableau_donnee["produit_interne"] = 1;
$tableau_donnee["date"] = $dateC->format("Y-m-d H:i:s");
$tableau_donnee["reference"] = $article->getReference()."-".time();
$tableau_donnee["ral_fournisseur"] = "0";
$tableau_donnee["parent_id"] = $article->getId();
$tableau_donnee["libelle"] = $article->getLibelle();
$tableau_donnee["reference_client"] = $article->getReferenceClient();
$tableau_donnee["reference_fournisseur"] = $article->getReferenceFournisseur();
$tableau_donnee["prix_base"] = $article->getPrixBase();
if ($article->getDateMaj() != "") {
$tableau_donnee["date_maj"] = $article->getDateMaj()->format("Y-m-d H:i:s");
}
if ($article->getDateMajPrix() != "") {
$tableau_donnee["date_maj_prix"] = $article->getDateMajPrix()->format("Y-m-d H:i:s");
}
if ($article->getDateSuppression() != "") {
$tableau_donnee["date_supression"] = $article->getDateSuppression()->format("Y-m-d H:i:s");
}
if (is_object($article->getMarque())) {
$tableau_donnee["marque_id"] = $article->getMarque()->getId();
}
$tableau_donnee["description"] = $article->getDescription();
$tableau_donnee["description_courte"] = $article->getDescriptionCourte();
$tableau_donnee["stock"] = "0";
if ($article->getStatut() === true) {
$tableau_donnee["statut"] = 1;
} else {
$tableau_donnee["statut"] = 0;
}
$tableau_donnee["largeur"] = $article->getLargeur();
$tableau_donnee["profondeur"] = $article->getProfondeur();
$tableau_donnee["hauteur"] = $article->getHauteur();
$tableau_donnee["poids"] = $article->getPoids();
if ($article->getAConsigner() === true) {
$tableau_donnee["a_consigner"] = 1;
} else {
$tableau_donnee["a_consigner"] = 0;
}
if ($article->getStockAuto()) {
$tableau_donnee["stock_auto"] = 1;
} else {
$tableau_donnee["stock_auto"] = 0;
}
if ($article->getArretGamme()) {
$tableau_donnee["arret_gamme"] = "1";
} else {
$tableau_donnee["arret_gamme"] = "0";
}
if (is_object($article->getUtilisateur())) {
$tableau_donnee["utilisateur_id"] = $article->getUtilisateur()->getId();
}
if (is_object($article->getRegleTaxe())) {
$tableau_donnee["regle_taxe_id"] = $article->getRegleTaxe()->getId();
}
$tableau_donnee["remise_max"] = $article->getRemiseMax();
$tableau_donnee["type_remise_max"] = $article->getTypeRemiseMax();
$tableau_donnee["seuil_commande_f_mini"] = $article->getSeuilMiniCommandeFournisseur();
$tableau_donnee["seuil_commande_f_maxi"] = $article->getSeuilMaxiCommandeFournisseur();
if (is_object($article->getNiveauUn())) {
$tableau_donnee["niveau_un_id"] = $article->getNiveauUn()->getId();
}
if (is_object($article->getNiveauDeux())) {
$tableau_donnee["niveau_deux_id"] = $article->getNiveauDeux()->getId();
}
if (is_object($article->getNiveauTrois())) {
$tableau_donnee["niveau_trois_id"] = $article->getNiveauTrois()->getId();
}
if (is_object($article->getNiveauQuatre())) {
$tableau_donnee["niveau_quatre_id"] = $article->getNiveauQuatre()->getId();
}
$tableau_donnee["pump"] = $article->getCpump();
$tableau_donnee["commentaire"] = $article->getCommentairePonctuel();
if ($article->getVirtuel() === true) {
$tableau_donnee["virtuel"] = 1;
} else {
$tableau_donnee["virtuel"] = 0;
}
//$tableau_donnee["prix_vente"]=$article->getLibelle();
$tableau_donnee["prix_vente"] = 0;
$tableau_donnee["taux_marge"] = $article->getTauxMarge();
$tableau_donnee["marge"] = $article->getMarge();
$tableau_donnee["marge_reelle"] = $article->getMargeReelle();
$tableau_donnee["ecotaxe"] = $article->getEcotaxe();
$tableau_donnee["conditionnement"] = $article->getConditionnement();
$tableau_donnee["stock_reserve"] = "0";
if (is_object($article->getFournisseurDefaut())) {
$tableau_donnee["fournisseur_defaut_id"] = $article->getFournisseurDefaut()->getId();
}
$tableau_donnee["ral_fournisseur"] = "0";
$tableau_donnee["id_import"] = "";
$tableau_donnee["donnees_import"] = "";
if ($article->getMajPrix()) {
$tableau_donnee["maj_prix"] = 1;
} else {
$tableau_donnee["maj_prix"] = 0;
}
if (is_object($article->getUniteMesure())) {
$tableau_donnee["unite_mesure_id"] = $article->getUniteMesure()->getId();
}
if ($article->getAfficherComposantPdfInterne() === true) {
$tableau_donnee["afficher_composant_pdf_interne"] = 1;
} else {
$tableau_donnee["afficher_composant_pdf_interne"] = 0;
}
if ($article->getAfficherComposantPdfExterne() === true) {
$tableau_donnee["afficher_composant_pdf_externe"] = 1;
} else {
$tableau_donnee["afficher_composant_pdf_externe"] = 0;
}
if (is_object($article->getCategorieRemiseArticle())) {
$tableau_donnee["categorie_remise_article_id"] = $article->getCategorieRemiseArticle()->getId();
}
if ($article->getTemporaire()) {
$tableau_donnee["temporaire"] = 1;
} else {
$tableau_donnee["temporaire"] = null;
}
$tableau_donnee["libelle_secondaire"] = $article->getLibelleSecondaire();
$tableau_donnee["a_commander"] = "1";
$tableau_donnee["a_fabriquer"] = "0";
$tableau_donnee["quantite_conseillee_mini"] = $article->getQuantiteConseilleeMini();
$tableau_donnee["quantite_conseillee"] = $article->getQuantiteConseillee();
$tableau_donnee["quantite_conseillee_maxi"] = $article->getQuantiteConseilleeMaxi();
if ($article->getArchive()) {
$tableau_donnee["archive"] = "1";
} else {
$tableau_donnee["archive"] = "0";
}
//$tableau_donnee["archive"]=$article->getArchive();
$tableau_donnee["coefficient_px_base_px_vente"] = $article->getCoefficientPrixBaseVente();
$tableau_donnee["nom_web"] = $article->getNomWeb();
$tableau_donnee["reference_web"] = $article->getReferenceWeb();
$tableau_donnee["reference_fournisseur_web"] = $article->getReferenceFournisseurWeb();
$tableau_donnee["description_web"] = $article->getDescriptionWeb();
$tableau_donnee["resume_web"] = $article->getResumeWeb();
$tableau_donnee["frais_ports_texte_web"] = $article->getFraisPortsTexteWeb();
$tableau_donnee["message_qd_en_stock"] = $article->getMessageQdEnStockWeb();
if (is_object($article->getArticleEnconsigne())) {
$tableau_donnee["article_enconsigne_id"] = $article->getArticleEnconsigne()->getId();
}
$tableau_donnee["reference_appel_1"] = $article->getReferenceAppel1();
$tableau_donnee["reference_appel_2"] = $article->getReferenceAppel2();
$tableau_donnee["reference_appel_3"] = $article->getReferenceAppel3();
$tableau_donnee["reference_appel_4"] = $article->getReferenceAppel4();
$tableau_donnee["reference_appel_5"] = $article->getReferenceAppel5();
$tableau_donnee["reference_appel_6"] = $article->getReferenceAppel6();
$tableau_donnee["reference_appel_7"] = $article->getReferenceAppel7();
$tableau_donnee["reference_appel_8"] = $article->getReferenceAppel8();
$tableau_donnee["reference_appel_9"] = $article->getReferenceAppel9();
$tableau_donnee["reference_appel_10"] = $article->getReferenceAppel10();
$tableau_donnee["reference_appel_11"] = $article->getReferenceAppel11();
if ($article->getMainOeuvre()) {
$tableau_donnee["main_oeuvre"] = "1";
} else {
$tableau_donnee["main_oeuvre"] = "0";
}
//$tableau_donnee["main_oeuvre"]=$article->getMainOeuvre();
$tableau_donnee["stock_reserve_fabrication"] = $article->getStockReserveFabrication();
if (is_object($article->getType())) {
$tableau_donnee["type_id"] = $article->getType()->getId();
}
if (is_object($article->getFamilleCompta())) {
$tableau_donnee["famille_compta_id"] = $article->getFamilleCompta()->getId();
}
if ($article->getPrestation() === true) {
$tableau_donnee["prestation"] = 1;
} else {
$tableau_donnee["prestation"] = 0;
}
if ($article->getNonStocke()) {
$tableau_donnee["non_stocke"] = "1";
} else {
$tableau_donnee["non_stocke"] = "0";
}
//$tableau_donnee["non_stocke"]=$article->getNonStocke();
if ($article->getNonCommandable() === true) {
$tableau_donnee["non_commandable"] = 1;
} else {
$tableau_donnee["non_commandable"] = 0;
}
if (is_object($article->getParent())) {
$tableau_donnee["parent_id"] = $article->getParent()->getId();
}
if ($article->getDivers()) {
$tableau_donnee["divers"] = 1;
} else {
$tableau_donnee["divers"] = 0;
}
if ($article->getMouvemente()) {
$tableau_donnee["mouvemente"] = "1";
} else {
$tableau_donnee["mouvemente"] = "0";
}
//$tableau_donnee["mouvemente"]=$article->getMouvemente();
if ($article->getNumSerieObligatoire() === true) {
$tableau_donnee["num_serie_obligatoire"] = 1;
} else {
$tableau_donnee["num_serie_obligatoire"] = 0;
}
if (is_object($article->getArticleRemplacement())) {
$tableau_donnee["article_remplacement_id"] = $article->getArticleRemplacement()->getId();
}
if ($article->getMajPoids()) {
$tableau_donnee["maj_poids"] = 1;
} else {
$tableau_donnee["maj_poids"] = 0;
}
if ($article->getMajPrixBase()) {
$tableau_donnee["maj_prix_base"] = 1;
} else {
$tableau_donnee["maj_prix_base"] = 0;
}
if ($article->getEstCommentaire()) {
$tableau_donnee["est_commentaire"] = 1;
} else {
$tableau_donnee["est_commentaire"] = 0;
}
$tableau_donnee["cond_achat"] = $article->getConditionnementAchat();
$tableau_donnee["seuil_critique"] = $article->getSeuilCritique();
$conn->insert('article__article', $tableau_donnee);
$idNouveauArticle = $conn->lastInsertId();
$article = $repo_article->find($idNouveauArticle);
} elseif ($article->getDivers() == 1) {
/*
$articleTmp = clone $article;
$newRef = $articleTmp->getReference().'-'.time();
$articleTmp->setReference($newRef);
$articleTmp->setParent($article);
$articleTmp->setIdImport($article->getIdImport().'-duplique');
$em->persist($articleTmp);
$em->flush();
$article = $articleTmp;
*/
$dateC = new \Datetime();
$conn = $em->getConnection();
$conn->getConfiguration()->setSQLLogger(null);
$tableau_donnee = [];
$tableau_donnee["date"] = $dateC->format("Y-m-d H:i:s");
$tableau_donnee["reference"] = $article->getReference()."-".time();
$tableau_donnee["ral_fournisseur"] = "0";
$tableau_donnee["parent_id"] = $article->getId();
$tableau_donnee["libelle"] = $article->getLibelle();
$tableau_donnee["reference_client"] = $article->getReferenceClient();
$tableau_donnee["reference_fournisseur"] = $article->getReferenceFournisseur();
$tableau_donnee["prix_base"] = $article->getPrixBase();
if ($article->getDateMaj() != "") {
$tableau_donnee["date_maj"] = $article->getDateMaj()->format("Y-m-d H:i:s");
}
if ($article->getDateMajPrix() != "") {
$tableau_donnee["date_maj_prix"] = $article->getDateMajPrix()->format("Y-m-d H:i:s");
}
if ($article->getDateSuppression() != "") {
$tableau_donnee["date_supression"] = $article->getDateSuppression()->format("Y-m-d H:i:s");
}
if (is_object($article->getMarque())) {
$tableau_donnee["marque_id"] = $article->getMarque()->getId();
}
$tableau_donnee["description"] = $article->getDescription();
$tableau_donnee["description_courte"] = $article->getDescriptionCourte();
$tableau_donnee["stock"] = "0";
if ($article->getStatut() === true) {
$tableau_donnee["statut"] = 1;
} else {
$tableau_donnee["statut"] = 0;
}
$tableau_donnee["largeur"] = $article->getLargeur();
$tableau_donnee["profondeur"] = $article->getProfondeur();
$tableau_donnee["hauteur"] = $article->getHauteur();
$tableau_donnee["poids"] = $article->getPoids();
if ($article->getAConsigner() === true) {
$tableau_donnee["a_consigner"] = 1;
} else {
$tableau_donnee["a_consigner"] = 0;
}
if ($article->getStockAuto()) {
$tableau_donnee["stock_auto"] = 1;
} else {
$tableau_donnee["stock_auto"] = 0;
}
if ($article->getArretGamme()) {
$tableau_donnee["arret_gamme"] = "1";
} else {
$tableau_donnee["arret_gamme"] = "0";
}
if (is_object($article->getUtilisateur())) {
$tableau_donnee["utilisateur_id"] = $article->getUtilisateur()->getId();
}
if (is_object($article->getRegleTaxe())) {
$tableau_donnee["regle_taxe_id"] = $article->getRegleTaxe()->getId();
}
$tableau_donnee["remise_max"] = $article->getRemiseMax();
$tableau_donnee["type_remise_max"] = $article->getTypeRemiseMax();
$tableau_donnee["seuil_commande_f_mini"] = $article->getSeuilMiniCommandeFournisseur();
$tableau_donnee["seuil_commande_f_maxi"] = $article->getSeuilMaxiCommandeFournisseur();
if (is_object($article->getNiveauUn())) {
$tableau_donnee["niveau_un_id"] = $article->getNiveauUn()->getId();
}
if (is_object($article->getNiveauDeux())) {
$tableau_donnee["niveau_deux_id"] = $article->getNiveauDeux()->getId();
}
if (is_object($article->getNiveauTrois())) {
$tableau_donnee["niveau_trois_id"] = $article->getNiveauTrois()->getId();
}
if (is_object($article->getNiveauQuatre())) {
$tableau_donnee["niveau_quatre_id"] = $article->getNiveauQuatre()->getId();
}
$tableau_donnee["pump"] = $article->getCpump();
$tableau_donnee["commentaire"] = $article->getCommentairePonctuel();
if ($article->getVirtuel() === true) {
$tableau_donnee["virtuel"] = 1;
} else {
$tableau_donnee["virtuel"] = 0;
}
//$tableau_donnee["prix_vente"]=$article->getLibelle();
$tableau_donnee["prix_vente"] = 0;
$tableau_donnee["taux_marge"] = $article->getTauxMarge();
$tableau_donnee["marge"] = $article->getMarge();
$tableau_donnee["marge_reelle"] = $article->getMargeReelle();
$tableau_donnee["ecotaxe"] = $article->getEcotaxe();
$tableau_donnee["conditionnement"] = $article->getConditionnement();
$tableau_donnee["stock_reserve"] = $article->getStockReserve();
if (is_object($article->getFournisseurDefaut())) {
$tableau_donnee["fournisseur_defaut_id"] = $article->getFournisseurDefaut()->getId();
}
$tableau_donnee["ral_fournisseur"] = "0";
$tableau_donnee["id_import"] = "";
$tableau_donnee["donnees_import"] = "";
if ($article->getMajPrix()) {
$tableau_donnee["maj_prix"] = 1;
} else {
$tableau_donnee["maj_prix"] = 0;
}
if (is_object($article->getUniteMesure())) {
$tableau_donnee["unite_mesure_id"] = $article->getUniteMesure()->getId();
}
if ($article->getAfficherComposantPdfInterne() === true) {
$tableau_donnee["afficher_composant_pdf_interne"] = 1;
} else {
$tableau_donnee["afficher_composant_pdf_interne"] = 0;
}
if ($article->getAfficherComposantPdfExterne() === true) {
$tableau_donnee["afficher_composant_pdf_externe"] = 1;
} else {
$tableau_donnee["afficher_composant_pdf_externe"] = 0;
}
if (is_object($article->getCategorieRemiseArticle())) {
$tableau_donnee["categorie_remise_article_id"] = $article->getCategorieRemiseArticle()->getId();
}
if ($article->getTemporaire()) {
$tableau_donnee["temporaire"] = 1;
} else {
$tableau_donnee["temporaire"] = null;
}
$tableau_donnee["libelle_secondaire"] = $article->getLibelleSecondaire();
$tableau_donnee["a_commander"] = "1";
$tableau_donnee["a_fabriquer"] = "0";
$tableau_donnee["quantite_conseillee_mini"] = $article->getQuantiteConseilleeMini();
$tableau_donnee["quantite_conseillee"] = $article->getQuantiteConseillee();
$tableau_donnee["quantite_conseillee_maxi"] = $article->getQuantiteConseilleeMaxi();
if ($article->getArchive()) {
$tableau_donnee["archive"] = "1";
} else {
$tableau_donnee["archive"] = "0";
}
//$tableau_donnee["archive"]=$article->getArchive();
$tableau_donnee["coefficient_px_base_px_vente"] = $article->getCoefficientPrixBaseVente();
$tableau_donnee["nom_web"] = $article->getNomWeb();
$tableau_donnee["reference_web"] = $article->getReferenceWeb();
$tableau_donnee["reference_fournisseur_web"] = $article->getReferenceFournisseurWeb();
$tableau_donnee["description_web"] = $article->getDescriptionWeb();
$tableau_donnee["resume_web"] = $article->getResumeWeb();
$tableau_donnee["frais_ports_texte_web"] = $article->getFraisPortsTexteWeb();
$tableau_donnee["message_qd_en_stock"] = $article->getMessageQdEnStockWeb();
if (is_object($article->getArticleEnconsigne())) {
$tableau_donnee["article_enconsigne_id"] = $article->getArticleEnconsigne()->getId();
}
$tableau_donnee["reference_appel_1"] = $article->getReferenceAppel1();
$tableau_donnee["reference_appel_2"] = $article->getReferenceAppel2();
$tableau_donnee["reference_appel_3"] = $article->getReferenceAppel3();
$tableau_donnee["reference_appel_4"] = $article->getReferenceAppel4();
$tableau_donnee["reference_appel_5"] = $article->getReferenceAppel5();
$tableau_donnee["reference_appel_6"] = $article->getReferenceAppel6();
$tableau_donnee["reference_appel_7"] = $article->getReferenceAppel7();
$tableau_donnee["reference_appel_8"] = $article->getReferenceAppel8();
$tableau_donnee["reference_appel_9"] = $article->getReferenceAppel9();
$tableau_donnee["reference_appel_10"] = $article->getReferenceAppel10();
$tableau_donnee["reference_appel_11"] = $article->getReferenceAppel11();
if ($article->getMainOeuvre()) {
$tableau_donnee["main_oeuvre"] = "1";
} else {
$tableau_donnee["main_oeuvre"] = "0";
}
//$tableau_donnee["main_oeuvre"]=$article->getMainOeuvre();
$tableau_donnee["stock_reserve_fabrication"] = $article->getStockReserveFabrication();
if (is_object($article->getType())) {
$tableau_donnee["type_id"] = $article->getType()->getId();
}
if (is_object($article->getFamilleCompta())) {
$tableau_donnee["famille_compta_id"] = $article->getFamilleCompta()->getId();
}
if ($article->getPrestation() === true) {
$tableau_donnee["prestation"] = 1;
} else {
$tableau_donnee["prestation"] = 0;
}
if ($article->getNonStocke()) {
$tableau_donnee["non_stocke"] = "1";
} else {
$tableau_donnee["non_stocke"] = "0";
}
//$tableau_donnee["non_stocke"]=$article->getNonStocke();
if ($article->getNonCommandable() === true) {
$tableau_donnee["non_commandable"] = 1;
} else {
$tableau_donnee["non_commandable"] = 0;
}
if (is_object($article->getParent())) {
$tableau_donnee["parent_id"] = $article->getParent()->getId();
}
if ($article->getDivers()) {
$tableau_donnee["divers"] = 1;
} else {
$tableau_donnee["divers"] = 0;
}
if ($article->getMouvemente()) {
$tableau_donnee["mouvemente"] = "1";
} else {
$tableau_donnee["mouvemente"] = "0";
}
//$tableau_donnee["mouvemente"]=$article->getMouvemente();
if ($article->getNumSerieObligatoire() === true) {
$tableau_donnee["num_serie_obligatoire"] = 1;
} else {
$tableau_donnee["num_serie_obligatoire"] = 0;
}
if (is_object($article->getArticleRemplacement())) {
$tableau_donnee["article_remplacement_id"] = $article->getArticleRemplacement()->getId();
}
if ($article->getMajPoids()) {
$tableau_donnee["maj_poids"] = 1;
} else {
$tableau_donnee["maj_poids"] = 0;
}
if ($article->getMajPrixBase()) {
$tableau_donnee["maj_prix_base"] = 1;
} else {
$tableau_donnee["maj_prix_base"] = 0;
}
if ($article->getEstCommentaire()) {
$tableau_donnee["est_commentaire"] = 1;
} else {
$tableau_donnee["est_commentaire"] = 0;
}
$tableau_donnee["cond_achat"] = $article->getConditionnementAchat();
$tableau_donnee["seuil_critique"] = $article->getSeuilCritique();
$conn->insert('article__article', $tableau_donnee);
$idNouveauArticle = $conn->lastInsertId();
$article = $repo_article->find($idNouveauArticle);
}
if ($article->getArretGamme() and is_object($article->getArticleRemplacement())) {
$stockEpuise = $article->getStock() - $article->getStockReserve();
while ($stockEpuise <= 0 && $article->getArretGamme() and is_object($article->getArticleRemplacement())) {
$article = $article->getArticleRemplacement();
$stockEpuise = $article->getStock() - $article->getStockReserve();
}
}
$commande = null;
if ($commandeId != '') {
$commande = $repo_commande->find($commandeId);
//$type = 'commande';
}
$a['position'] = 0;
if (is_object($commande)) {
$a['commande'] = $commande;
$a['position'] = count($commande->getArticleCommande());
} else {
$a['commande'] = null;
}
$a['action'] = "insert";
$a['article'] = $article;
$a['libelle'] = $article->getLibelle();
$a['libelleSecondaire'] = $article->getLibelleSecondaire();
//$a['ecocontribution']= floatval($article->getEcocontribution());
$a['ecocontribution'] = 0;
$a['fraisPort'] = "0";
if ($quantite != '' && is_numeric($quantite)) {
$a['quantite'] = $quantite;
$a['quantitePrepa'] = $quantite;
} else {
if ($article->getConditionnement() > 0) {
$a['quantite'] = $article->getConditionnement();
$a['quantitePrepa'] = $article->getConditionnement();
} else {
$repo_cond_vente = $em->getRepository(ConditionVente::class);
$condVenteMini = $repo_cond_vente->findQuantiteMini($article, "", $adresse);
if (is_object($condVenteMini)) {
$a['quantite'] = $condVenteMini->getDebut();
$a['quantitePrepa'] = $condVenteMini->getDebut();
} elseif ($article->getConditionnement() > 0) {
$a['quantite'] = $article->getConditionnement();
$a['quantitePrepa'] = $article->getConditionnement();
} else {
$a['quantite'] = "1";
$a['quantitePrepa'] = "1";
}
//$a['quantite']="1";
//$a['quantitePrepa']="1";
}
}
$a['ralClient'] = $a['quantite'];
$a['quantiteDispo'] = $a['quantite'];
$client = '';
if ($client_id != '') {
$client = $repo_client->find($client_id);
if (is_object($client)) {
$variables['client'] = $client;
if (is_object($client->getLangue())) {
$repo_trad = $em->getRepository(Traduction::class);
$trad = $repo_trad->findOneBy(["article" => $article, "langue" => $client->getLangue()]);
if (is_object($trad)) {
$a['libelle'] = $trad->getLibelle();
$a['libelleSecondaire'] = $trad->getLibelleSecondaire();
}
}
}
}
if ($article->getEstCommentaire()) {
$a['estCommentaire'] = 1;
} else {
$a['estCommentaire'] = 0;
}
$a['commentaire'] = "";
$a['commentaireSuppl'] = "";
$a['commentairePrive'] = "";
$a['remise'] = "0";
$a['remiseSupplementaire'] = "0";
$a['totalHt'] = floatval($article->getPrixVente());
$a['totalHtV2'] = floatval($article->getPrixVente());
$quantiteSurCommande = floatval($quantiteSurCommande) + $a['quantite'];
$a['couleur'] = $serviceArticle->getCouleurEtatStock($article, $quantiteSurCommande);
$a['quantiteDejaPreparee'] = 0;
$a['transporteur'] = $article->getTransporteur();
$a['poids'] = floatval($article->getPoids());
$taxe = $serviceArticle->getTaxe($article, $client, $adresse);
if (is_object($taxe)) {
$a['taxe'] = $taxe;
$a['tva'] = $taxe->getTaux();
}
//sauvegarde auto
if (is_object($commande)) {
$enregAuto = true;
//modification des donnees pour l'enregistrement
$a['prix_base'] = floatval($article->getPrixVente());
if (is_object($a['article'])) {
$a['article_id'] = $a['article']->getId();
}
if (is_object($a['transporteur'])) {
$a['transporteur_id'] = $a['transporteur']->getId();
}
if (is_object($a['commande'])) {
$a['commande_id'] = $a['commande']->getId();
}
$a['libelle_secondaire'] = $a['libelleSecondaire'];
$a['frais_port'] = $a['fraisPort'];
$a['ral_client'] = $a['ralClient'];
//$a['est_commentaire'] = $a['estCommentaire'];
$a['commentaire_suppl'] = $a['commentaireSuppl'];
$a['commentaire_prive'] = $a['commentairePrive'];
$a['remise_supplementaire'] = $a['remiseSupplementaire'];
$a['total_ht'] = $a['totalHt'];
//$a['total_ht_v2'] = $a['totalHtV2'];
$a['quantite_deja_preparee'] = $a['quantiteDejaPreparee'];
$a['quantite_dispo'] = $a['quantiteDispo'];
$a['date'] = (new \Datetime)->format('Y-m-d H:i:s');
if (array_key_exists('taxe', $a) && is_object($a['taxe'])) {
$a['taxe_id'] = $a['taxe']->getId();
}
unset($a['remise']);
unset($a['transporteur']);
unset($a['article']);
unset($a['commande']);
unset($a['action']);
unset($a['libelleSecondaire']);
unset($a['fraisPort']);
unset($a['quantitePrepa']);
unset($a['ralClient']);
unset($a['estCommentaire']);
unset($a['commentaireSuppl']);
unset($a['commentairePrive']);
unset($a['remiseSupplementaire']);
unset($a['totalHt']);
unset($a['totalHtV2']);
unset($a['couleur']);
unset($a['quantiteDejaPreparee']);
unset($a['quantiteDispo']);
if (array_key_exists('taxe', $a)) {
unset($a['taxe']);
}
//print_r($a);
$conn->insert('commerciale__article_commande', $a);
//$a['id'] = $conn->lastInsertId();
$a = $repo_article_commande->find($conn->lastInsertId());
$commandeService->creerHistorique($commande, 'ajout-ligne', ['articleCommande' => $a]);
//echo "toto";
if ($countTmp == 0) {
$articleCommandeAssocie = $conn->lastInsertId();
} else {
//$a['articleCommandeAssocie']['id'] = $idArticleCommandeTmp;
//$a->setArticleCommandeAssocie($articleCommandeAssocie);
$articleCommandeAssocie = $conn->lastInsertId();
}
//reservation de stock
if (is_int($commande->getTypeDocumentCommercial()) && in_array($commande->getTypeDocumentCommercial(), [TypeDocumentCommercial::COMMANDE])) {
$type = 'commande';
$ralClientArtComm = floatval($a->getQuantite());
$reserve = $ralClientArtComm + floatval($article->getStockReserve());
if ($article->getVirtuel() == true or $article->getNonStocke() == true or $article->getNonCommandable() == true or $article->getMainOeuvre() == true) {
$article->setStockReserve(0);
if ($article->getProduitInterne() == true) {
$variation = floatval($a->getQuantite());
$serviceArticle->modifierStockReserveComposants($article, $variation);
}
} elseif (floatval($a->getQuantite()) != 0) {
$article->setStockReserve($reserve);
$em->persist($article);
}
$em->flush();
}
} else {
if ($countTmp == 0) {
$a['id'] = $idArticleCommandeTmp;
} else {
$a['articleCommandeAssocie']['id'] = $idArticleCommandeTmp;
}
}
$countTmp++;
$variables = [
'a' => $a,
'boucle' => "0",
'numeroLigne' => "0",
'tabColonneUser' => $tabColonneUser,
'colspan' => $colspan,
'type' => $type,
'enregAuto' => $enregAuto,
'adresse' => $adresse,
];
if ($client_id != '') {
$client = $repo_client->find($client_id);
if (is_object($client)) {
$variables['client'] = $client;
}
}
if ($cible == "or") {
$rendu .= $this->renderView('GestionComerciale/ArticleCommande/template_or_tr.html.twig', $variables);
} elseif ($cible == "regularisation") {
$rendu .= $this->renderView('GestionComerciale/ArticleCommande/template_regulation_tr.html.twig', $variables);
} else {
$rendu .= $this->renderView('GestionComerciale/ArticleCommande/template_tr.html.twig', $variables);
}
$commentairePonctuel .= $article->getCommentairePonctuel();
$stockEpuise = $article->getStock() - $article->getStockReserve();
if ($article->getArretGamme() && $stockEpuise <= 0) {
$commentairePonctuel .= "<div>Article en arrêt de gamme sans article de remplacement.</div>";
}
if (floatVal($article->getPrixVente()) < floatVal($article->getCpump())) {
//message_popin += ">Attention : Le prix de vente "+parseFloat(donnees[0].prixVente)+" € est inférieur au PUMP "+parseFloat(donnees[0].pump)+". €<br/>";
//$commentairePonctuel .= "<div>Le prix de vente (".floatVal($article->getPrixVente())." €) est inférieur au PUMP (".round(floatVal($article->getPump()),2)." €)</div>";
}
if ($article->getAConsigner() == "1" and is_object($article->getArticleEnConsigne())) {
$consigne = $article->getArticleEnConsigne()->getId();
}
}
$articleCommentaire = 0;
if ($article->getEstCommentaire()) {
$articleCommentaire = 1;
}
return new JsonResponse([
'consigne' => $consigne,
'rendu' => $rendu,
'id' => $article->getId(),
'articleCommentaire' => $articleCommentaire,
'commentairePonctuel' => $commentairePonctuel,
'couleur' => '',
'type' => $type,
]);
}
/**
* @Route("/commande-fournisseur-reprise-article/nouveau/{id}", name="dtc_construire_ligne_article_commande_fournisseur_reprise")
*/
public function construireLigneArticleCommandeFournisseurRepriseAction(Request $request, ArticleCommande $articleCommande, EntityManagerInterface $em,
ArticleService $articleService, ArticleService $serviceArticle, DateService $dateService,
FournisseurService $fournisseurService, ColonneTableauService $serviceColonne
) {
$em = $this->getDoctrine();
$conn = $em->getConnection();
$conn->getConfiguration()->setSQLLogger(null);
$repoFournisseur = $em->getRepository(Fournisseur::class);
$repo_taxe = $em->getRepository(Taxe::class);
$fournisseur = $request->query->get('fournisseur');
$articlesCommandeSource = $request->query->get('articlesCommandeSource');
$fournisseur = $articleCommande->getCommandeFournisseur()->getFournisseur()->getId();
$repo_article_commande = $em->getRepository(ArticleCommande::class);
$articlesCommandeSource_obj = $repo_article_commande->find($articlesCommandeSource);
$commandeId = $request->query->get('commandeId');;
$quantite = $request->query->get('quantite');
$repo_article = $em->getRepository(Article::class);
$article = $articleCommande->getArticle();
$quantite = $request->query->get('quantite');
$quantiteSurCommande = $request->query->get('quantiteSurCommande');
$client_id = $request->query->get('client');
$cible = $request->query->get('cible');
$articlesCommandeSource = $request->query->get('articlesCommandeSource');
$type = '';
$repo_article_commande = $em->getRepository(ArticleCommande::class);
$articlesCommandeSource_obj = $repo_article_commande->find($articlesCommandeSource);
if (1 != 1 and $article->getDivers() == 1 && ! is_object($article->getParent())) {
$conn = $em->getConnection();
$conn->getConfiguration()->setSQLLogger(null);
$referenceDivers = $articleService->getReferenceDivers($article);
$tableau_donnee = [];
$tableau_donnee["reference"] = $article->getReference()."-".$referenceDivers['reference'];
$tableau_donnee["numero_reference"] = $referenceDivers['numero_reference'];
$tableau_donnee["ral_fournisseur"] = "0";
$tableau_donnee["parent_id"] = $article->getId();
$tableau_donnee["libelle"] = $article->getLibelle();
$tableau_donnee["reference_client"] = $article->getReferenceClient();
$tableau_donnee["reference_fournisseur"] = $article->getReferenceFournisseur();
$tableau_donnee["prix_base"] = $article->getPrixBase();
$dateTmp = new \Datetime;
$tableau_donnee["date"] = $dateTmp->format("Y-m-d H:i:s");
if ($article->getDateMaj() != "") {
$tableau_donnee["date_maj"] = $article->getDateMaj()->format("Y-m-d H:i:s");
}
if ($article->getDateMajPrix() != "") {
$tableau_donnee["date_maj_prix"] = $article->getDateMajPrix()->format("Y-m-d H:i:s");
}
if ($article->getDateSuppression() != "") {
$tableau_donnee["date_supression"] = $article->getDateSuppression()->format("Y-m-d H:i:s");
}
if (is_object($article->getMarque())) {
$tableau_donnee["marque_id"] = $article->getMarque()->getId();
}
$tableau_donnee["description"] = $article->getDescription();
$tableau_donnee["description_courte"] = $article->getDescriptionCourte();
$tableau_donnee["stock"] = "0";
if ($article->getStatut() === true) {
$tableau_donnee["statut"] = 1;
} else {
$tableau_donnee["statut"] = 0;
}
$tableau_donnee["largeur"] = $article->getLargeur();
$tableau_donnee["profondeur"] = $article->getProfondeur();
$tableau_donnee["hauteur"] = $article->getHauteur();
$tableau_donnee["poids"] = $article->getPoids();
if ($article->getAConsigner()) {
$tableau_donnee["a_consigner"] = 1;
} else {
$tableau_donnee["a_consigner"] = 0;
}
if ($article->getStockAuto()) {
$tableau_donnee["stock_auto"] = 1;
} else {
$tableau_donnee["stock_auto"] = 0;
}
if ($article->getArretGamme() === true) {
$tableau_donnee["arret_gamme"] = 1;
} else {
$tableau_donnee["arret_gamme"] = 0;
}
if (is_object($article->getUtilisateur())) {
$tableau_donnee["utilisateur_id"] = $article->getUtilisateur()->getId();
}
if (is_object($article->getRegleTaxe())) {
$tableau_donnee["regle_taxe_id"] = $article->getRegleTaxe()->getId();
}
$tableau_donnee["remise_max"] = $article->getRemiseMax();
$tableau_donnee["type_remise_max"] = $article->getTypeRemiseMax();
$tableau_donnee["seuil_commande_f_mini"] = $article->getSeuilMiniCommandeFournisseur();
$tableau_donnee["seuil_commande_f_maxi"] = $article->getSeuilMaxiCommandeFournisseur();
if (is_object($article->getNiveauUn())) {
$tableau_donnee["niveau_un_id"] = $article->getNiveauUn()->getId();
}
if (is_object($article->getNiveauDeux())) {
$tableau_donnee["niveau_deux_id"] = $article->getNiveauDeux()->getId();
}
if (is_object($article->getNiveauTrois())) {
$tableau_donnee["niveau_trois_id"] = $article->getNiveauTrois()->getId();
}
if (is_object($article->getNiveauQuatre())) {
$tableau_donnee["niveau_quatre_id"] = $article->getNiveauQuatre()->getId();
}
$tableau_donnee["pump"] = $article->getCpump();
$tableau_donnee["commentaire"] = $article->getCommentairePonctuel();
if ($article->getVirtuel()) {
$tableau_donnee["virtuel"] = 1;
} else {
$tableau_donnee["virtuel"] = 0;
}
//$tableau_donnee["prix_vente"]=$article->getLibelle();
$tableau_donnee["prix_vente"] = 0;
$tableau_donnee["taux_marge"] = $article->getTauxMarge();
$tableau_donnee["marge"] = $article->getMarge();
$tableau_donnee["marge_reelle"] = $article->getMargeReelle();
$tableau_donnee["ecotaxe"] = $article->getEcotaxe();
$tableau_donnee["conditionnement"] = $article->getConditionnement();
$tableau_donnee["stock_reserve"] = $article->getStockReserve();
if (is_object($article->getFournisseurDefaut())) {
$tableau_donnee["fournisseur_defaut_id"] = $article->getFournisseurDefaut()->getId();
}
$tableau_donnee["ral_fournisseur"] = "0";
$tableau_donnee["id_import"] = "";
$tableau_donnee["donnees_import"] = "";
if ($article->getMajPrix()) {
$tableau_donnee["maj_prix"] = 1;
} else {
$tableau_donnee["maj_prix"] = 0;
}
if (is_object($article->getUniteMesure())) {
$tableau_donnee["unite_mesure_id"] = $article->getUniteMesure()->getId();
}
if ($article->getAfficherComposantPdfInterne()) {
$tableau_donnee["afficher_composant_pdf_interne"] = 1;
} else {
$tableau_donnee["afficher_composant_pdf_interne"] = 0;
}
if ($article->getAfficherComposantPdfExterne()) {
$tableau_donnee["afficher_composant_pdf_externe"] = 1;
} else {
$tableau_donnee["afficher_composant_pdf_externe"] = 0;
}
if (is_object($article->getCategorieRemiseArticle())) {
$tableau_donnee["categorie_remise_article_id"] = $article->getCategorieRemiseArticle()->getId();
}
$tableau_donnee["temporaire"] = $article->getTemporaire();
$tableau_donnee["libelle_secondaire"] = $article->getLibelleSecondaire();
$tableau_donnee["a_commander"] = "1";
$tableau_donnee["a_fabriquer"] = "0";
$tableau_donnee["quantite_conseillee_mini"] = $article->getQuantiteConseilleeMini();
$tableau_donnee["quantite_conseillee"] = $article->getQuantiteConseillee();
$tableau_donnee["quantite_conseillee_maxi"] = $article->getQuantiteConseilleeMaxi();
if ($article->getArchive() === true) {
$tableau_donnee["archive"] = 1;
} else {
$tableau_donnee["archive"] = 0;
}
$tableau_donnee["coefficient_px_base_px_vente"] = $article->getCoefficientPrixBaseVente();
$tableau_donnee["nom_web"] = $article->getNomWeb();
$tableau_donnee["reference_web"] = $article->getReferenceWeb();
$tableau_donnee["reference_fournisseur_web"] = $article->getReferenceFournisseurWeb();
$tableau_donnee["description_web"] = $article->getDescriptionWeb();
$tableau_donnee["resume_web"] = $article->getResumeWeb();
$tableau_donnee["frais_ports_texte_web"] = $article->getFraisPortsTexteWeb();
$tableau_donnee["message_qd_en_stock"] = $article->getMessageQdEnStockWeb();
if (is_object($article->getArticleEnconsigne())) {
$tableau_donnee["article_enconsigne_id"] = $article->getArticleEnconsigne()->getId();
}
$tableau_donnee["reference_appel_1"] = $article->getReferenceAppel1();
$tableau_donnee["reference_appel_2"] = $article->getReferenceAppel2();
$tableau_donnee["reference_appel_3"] = $article->getReferenceAppel3();
$tableau_donnee["reference_appel_4"] = $article->getReferenceAppel4();
$tableau_donnee["reference_appel_5"] = $article->getReferenceAppel5();
$tableau_donnee["reference_appel_6"] = $article->getReferenceAppel6();
$tableau_donnee["reference_appel_7"] = $article->getReferenceAppel7();
$tableau_donnee["reference_appel_8"] = $article->getReferenceAppel8();
$tableau_donnee["reference_appel_9"] = $article->getReferenceAppel9();
$tableau_donnee["reference_appel_10"] = $article->getReferenceAppel10();
$tableau_donnee["reference_appel_11"] = $article->getReferenceAppel11();
if ($article->getMainOeuvre() === true) {
$tableau_donnee["main_oeuvre"] = 1;
} else {
$tableau_donnee["main_oeuvre"] = 0;
}
$tableau_donnee["stock_reserve_fabrication"] = $article->getStockReserveFabrication();
if (is_object($article->getType())) {
$tableau_donnee["type_id"] = $article->getType()->getId();
}
if (is_object($article->getFamilleCompta())) {
$tableau_donnee["famille_compta_id"] = $article->getFamilleCompta()->getId();
}
if ($article->getPrestation()) {
$tableau_donnee["prestation"] = 1;
} else {
$tableau_donnee["prestation"] = 0;
}
if ($article->getNonStocke() === true) {
$tableau_donnee["non_stocke"] = 1;
} else {
$tableau_donnee["non_stocke"] = 0;
}
if ($article->getNonCommandable()) {
$tableau_donnee["non_commandable"] = 1;
} else {
$tableau_donnee["non_commandable"] = 0;
}
if (is_object($article->getParent())) {
$tableau_donnee["parent_id"] = $article->getParent()->getId();
}
$tableau_donnee["divers"] = $article->getDivers();
if ($article->getMouvemente() === true) {
$tableau_donnee["mouvemente"] = 1;
} else {
$tableau_donnee["mouvemente"] = 0;
}
if ($article->getNumSerieObligatoire()) {
$tableau_donnee["num_serie_obligatoire"] = 1;
} else {
$tableau_donnee["num_serie_obligatoire"] = 0;
}
if (is_object($article->getArticleRemplacement())) {
$tableau_donnee["article_remplacement_id"] = $article->getArticleRemplacement()->getId();
}
if ($article->getMajPoids()) {
$tableau_donnee["maj_poids"] = 1;
} else {
$tableau_donnee["maj_poids"] = 0;
}
if ($article->getMajPrixBase()) {
$tableau_donnee["maj_prix_base"] = 1;
} else {
$tableau_donnee["maj_prix_base"] = 0;
}
if ($article->getEstCommentaire()) {
$tableau_donnee["est_commentaire"] = 1;
} else {
$tableau_donnee["est_commentaire"] = 0;
}
$tableau_donnee["cond_achat"] = $article->getConditionnementAchat();
$tableau_donnee["seuil_critique"] = $article->getSeuilCritique();
if (is_object($article->getRegleTaxeAchat())) {
$tableau_donnee["regle_taxe_achat_id"] = $article->getRegleTaxeAchat()->getId();
}
$tableau_donnee["maj_prix"] = 1;
$conn->insert('article__article', $tableau_donnee);
$idNouveauArticle = $conn->lastInsertId();
$article = $repo_article->find($idNouveauArticle);
}
$a = [];
//$a['id'] = 'tmp-'.time();
$a['position'] = "";
$a['article'] = $article;
$a['ecocontribution'] = floatval($article->getEcocontribution());
$a['libelle'] = $articleCommande->getLibelle();
$a['articleCommandeRepris'] = $articleCommande;
if ($quantite != '' && is_numeric($quantite)) {
$a['quantite'] = -$quantite;
$a['ral'] = -$quantite;
} else {
$a['quantite'] = "-1";
$a['ral'] = "-1";
}
//$a['estCommentaire']=$article->getEstCommentaire();
if ($article->getEstCommentaire()) {
$a['estCommentaire'] = 1;
} else {
$a['estCommentaire'] = 0;
}
$a['articleCommandeRepris'] = $articleCommande;
$a['commentaire'] = "Reprise sur facture n°".$articleCommande->getCommandeFournisseur()->getReference();
//$a['commentaire']="";
$a['commentaireSuppl'] = "";
$a['commentairePrive'] = "";
$a['remise'] = $articleCommande->getRemise();
$a['remiseSupplementaire'] = $articleCommande->getRemiseSupplementaire();
//$a['totalHt']=$article->getPrixBase();
$a['totalHt'] = -($articleCommande->getTotalHt() / $articleCommande->getQuantite() * $quantite);
//$a['totalHtV2'] = -($articleCommande->getTotalHt()/$articleCommande->getQuantite()*$quantite);
$a['prixBase'] = $articleCommande->getPrixBase();
$condition = '';
//recuperer la condition d'achat par défaut
$repoConditionsAchat = $em->getRepository(ConditionAchat::class);
//$condition = $repoConditionsAchat->findBy(array('article' => $article->getId(), 'defaut' => 1), array('id'=>'ASC'),1,0);
if ($fournisseur != '') {
$condition = $repoConditionsAchat->findOneBy([
'article' => $article->getId(),
'fournisseur' => $fournisseur,
'defaut' => 1,
]);
}
if ( ! isset($condition) || ! is_object($condition)) {
/*
$condition = $repoConditionsAchat->findOneBy(array('article' => $article->getId(),
'fournisseur' => $fournisseur,
));
*/
//$conditions = $repoConditionsAchat->findBy(array('article' => $article->getId(),'fournisseur' => $fournisseur,), array('quantite'=>'ASC'), 1, 0);
//if(count($conditions)) $condition = $conditions[0];
}
$condition = $articleCommande->getConditionAchat();
$a['coefficientConditionnement'] = 1;
$a['fraisAnnexes'] = 0;
$a['dateApproximativeReception'] = null;
if (is_object($condition)) {
$a['conditionAchat'] = $condition;
$a['fraisAnnexes'] = $condition->getFraisAnnexes();
}
if (is_object($condition) and 1 != 1) {
$a['coefficientConditionnement'] = $condition->getCoefficientConditionnement();
if ($condition->getPrixNet() and 1 != 1) {
$a['remise'] = "0";
$a['remiseSupplementaire'] = "0";
if ($condition->getPrixAchatNet() != '') {
//$a['prixBase']= $condition->getPrixAchatBrut() * $condition->getConditionnement() / $condition->getCoefficientConditionnement() ;
$a['prixBase'] = $condition->getPrixAchatNet();
}
} elseif (1 != 1) {
if ($condition->getTauxRemise() != '') {
$a['remise'] = $condition->getTauxRemise();
}
if ($condition->getTauxRemiseSupplementaire() != '') {
$a['remiseSupplementaire'] = $condition->getTauxRemiseSupplementaire();
}
if ($condition->getPrixAchatBrut() != '') {
//$a['prixBase']= $condition->getPrixAchatBrut() * $condition->getConditionnement() / $condition->getCoefficientConditionnement() ;
$a['prixBase'] = $condition->getPrixAchatBrut();
}
}
if ($condition->getLibelle() != '' and 1 != 1) {
$a['libelle'] = $condition->getLibelle();
}
if ($quantite != '' && is_numeric($quantite)) {
$a['quantite'] = -$quantite;
} elseif ($condition->getQuantite() != '' and 1 != 1) {
//$a['quantite']=$condition->getQuantite();
$conditionnement = 1;
if ($condition->getConditionnement() != '') {
$conditionnement = floatval($condition->getConditionnement());
}
$quantite = floatval($condition->getQuantite());
$i = 1;
while ($quantite % $conditionnement != 0) {
$quantite++;
}
$a['quantite'] = -$quantite;
$a['ral'] = -$quantite;
$a['referenceFournisseur'] = $condition->getReferenceFournisseur();
}
$a['conditionAchat'] = $condition;
$a['fraisAnnexes'] = $condition->getFraisAnnexes();
if (floatval($condition->getDelai()) > 0) {
$joursLivraison = ["lundi", "mardi", "mercredi", "jeudi", "vendredi"];
$dateLivraisonTheorique = $dateService->date_addWorkingDays(strtotime((new \Datetime)->format("Y-m-d")), floatval($condition->getDelai()), $joursLivraison);
//$a['dateApproximativeReception'] = (new \Datetime)->modify('+ '.floatval($condition->getDelai()).' days');
$a['dateApproximativeReception'] = $dateLivraisonTheorique;
}
}
$a['couleur'] = $serviceArticle->getCouleurEtatStock($article, $a['quantite']);
if ($fournisseur != "") {
$fournisseur = $repoFournisseur->find($fournisseur);
}
$taxe = $repo_taxe->find(5);
if (is_object($fournisseur)) {
$taxe = $fournisseurService->getTaxe($fournisseur, $article);
}
$a['tva'] = $taxe->getTaux();
$a['taxe'] = $taxe;
$a['tva'] = $articleCommande->getTva();
$a['taxe'] = $taxe;
if (is_object($articleCommande->getTaxe())) {
$a['taxe'] = $articleCommande->getTaxe();
}
$a['prixAchatUnitaireAvecFrais'] = $a['prixBase'];
//sauvegarde auto
if (is_object($articlesCommandeSource_obj) && is_object($articlesCommandeSource_obj->getCommandeFournisseur())) {
//modification des donnees pour l'enregistrement
} else {
$a['id'] = 'tmp-'.time();
}
//echo "JJJJ ".$fournisseur->getLibelle();
$colspan = 14;
$tabColonneUser = [];
$tabColonneUser["id"] = 1;
$tabColonneUser["reference"] = 1;
$tabColonneUser["referenceF"] = 1;
$tabColonneUser["libelle"] = 1;
$tabColonneUser["libelleF"] = 1;
$tabColonneUser["qteMini"] = 1;
$tabColonneUser["qteMaxi"] = 1;
$tabColonneUser["ralC"] = 1;
$tabColonneUser["ralF"] = 1;
$tabColonneUser["qteStockCommande"] = 1;
$tabColonneUser["uniteVente"] = 1;
$tabColonneUser["qte"] = 1;
$tabColonneUser["uniteAchat"] = 1;
$tabColonneUser["prixAchatUnitaire"] = 1;
$tabColonneUser["prixHT"] = 1;
$tabColonneUser["CC"] = 1;
$tabColonneUser["qteMiniAchat"] = 1;
$tabColonneUser["conditionnement"] = 1;
$tabColonneUser["txRem"] = 1;
$tabColonneUser["txRemSuppl"] = 1;
$tabColonneUser["fraisAnnexes"] = 1;
$tabColonneUser["ecocontribution"] = 1;
$tabColonneUser["montantHt"] = 1;
$tabColonneUser["totalHT"] = 1;
$tabColonneUser["pump"] = 1;
$tabColonneUser["stock"] = 1;
$tabColonneUser["dateApproximativeReception"] = 1;
// TODO CHANGE THIS
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormCommandeFournisseur";
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'id') == false) {
$colspan--;
$tabColonneUser["id"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'reference') == false) {
$colspan--;
$tabColonneUser["reference"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'referenceF') == false) {
$colspan--;
$tabColonneUser["referenceF"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'libelle') == false) {
$colspan--;
$tabColonneUser["libelle"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'libelleF') == false) {
$colspan--;
$tabColonneUser["libelleF"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'qteMini') == false) {
$colspan--;
$tabColonneUser["qteMini"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'qteMaxi') == false) {
$colspan--;
$tabColonneUser["qteMaxi"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'ralC') == false) {
$colspan--;
$tabColonneUser["ralC"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'ralF') == false) {
$colspan--;
$tabColonneUser["ralF"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'qteStockCommande') == false) {
$colspan--;
$tabColonneUser["qteStockCommande"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'uniteVente') == false) {
$colspan--;
$tabColonneUser["uniteVente"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'qte') == false) {
$colspan--;
$tabColonneUser["qte"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'uniteAchat') == false) {
$colspan--;
$tabColonneUser["uniteAchat"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'prixAchatUnitaire') == false) {
$colspan--;
$tabColonneUser["prixAchatUnitaire"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'prixHT') == false) {
$colspan--;
$tabColonneUser["prixHT"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'CC') == false) {
$colspan--;
$tabColonneUser["CC"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'qteMiniAchat') == false) {
$colspan--;
$tabColonneUser["qteMiniAchat"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'conditionnement') == false) {
$colspan--;
$tabColonneUser["conditionnement"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'txRem') == false) {
$colspan--;
$tabColonneUser["txRem"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'txRemSuppl') == false) {
$colspan--;
$tabColonneUser["txRemSuppl"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'fraisAnnexes') == false) {
$colspan--;
$tabColonneUser["fraisAnnexes"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'ecocontribution') == false) {
$colspan--;
$tabColonneUser["ecocontribution"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'montantHt') == false) {
$colspan--;
$tabColonneUser["montantHt"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'totalHT') == false) {
$colspan--;
$tabColonneUser["totalHT"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'pump') == false) {
$colspan--;
$tabColonneUser["pump"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'stock') == false) {
$colspan--;
$tabColonneUser["stock"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'dateApproximativeReception') == false) {
$colspan--;
$tabColonneUser["dateApproximativeReception"] = 0;
}
$rendu = $this->renderView('GestionComerciale/ArticleCommande/template_tr_fournisseur.html.twig', [
'a' => $a,
'boucle' => "0",
'numeroLigne' => "0",
'fournisseur' => $fournisseur,
'commandeId' => $commandeId,
'tabColonneUser' => $tabColonneUser,
]);
return new JsonResponse(['rendu' => $rendu, 'commentairePonctuel' => $article->getCommentairePonctuel()]);
}
/**
* @Route("/commande-reprise_article/nouveau/{id}", name="dtc_construire_ligne_article_commande_reprise")
*/
public function construireLigneArticleCommandeRepriseAction(Request $request, ArticleCommande $articleCommande, EntityManagerInterface $em,
ColonneTableauService $serviceColonne
) {
$conn = $em->getConnection();
$conn->getConfiguration()->setSQLLogger(null);
$article = $articleCommande->getArticle();
$quantite = $request->query->get('quantite');
$quantiteSurCommande = $request->query->get('quantiteSurCommande');
$client_id = $request->query->get('client');
$cible = $request->query->get('cible');
$articlesCommandeSource = $request->query->get('articlesCommandeSource');
$type = '';
$repo_article_commande = $em->getRepository(ArticleCommande::class);
$articlesCommandeSource_obj = $repo_article_commande->find($articlesCommandeSource);
//echo "toto ".$articlesCommandeSource;
//exit;
$repo_client = $em->getRepository(Client::class);
if ($article->getDivers() == 1) {
$articleTmp = clone $article;
$newRef = $articleTmp->getReference().'-'.time();
$articleTmp->setReference($newRef);
$articleTmp->setParent($article);
$articleTmp->setIdImport($article->getIdImport().'-duplique');
$em->persist($articleTmp);
$em->flush();
$article = $articleTmp;
}
$a = [];
$a['commande'] = "";
$a['quantiteDejaPreparee'] = 0;
$a['action'] = "insert";
$a['position'] = 0;
$a['article'] = $article;
$a['libelle'] = $articleCommande->getLibelle();
$a['libelleSecondaire'] = $articleCommande->getLibelleSecondaire();
$a['quantite'] = -$quantite;
$a['quantitePrepa'] = -$quantite;
$a['fraisPort'] = "0";
$a['articleCommandeRepris'] = $articleCommande;
$a['transporteur'] = $articleCommande->getTransporteur();
$a['estCommentaire'] = $article->getEstCommentaire();
$commande = $articleCommande->getCommande();
$date = date_format($commande->getDate(), 'd/m/Y');
$utilisateur = $commande->getUtilisateur();
$a['commentaire'] = "Reprise sur facture n° ".$commande->getReference()." du ".$date.' saisie par '.$utilisateur->getNom().' '.$utilisateur->getPrenom();
$a['commentaireSuppl'] = "";
$a['commentairePrive'] = "";
$a['prixBase'] = $articleCommande->getPrixBase();
$a['prixAchatUnitaireAvecFrais'] = $articleCommande->getPrixAchatUnitaireAvecFrais();
$a['remise'] = $articleCommande->getRemise();
$a['remiseSupplementaire'] = $articleCommande->getRemiseSupplementaire();
//$a['ecocontribution']= floatval($articleCommande->getEcocontribution());
$a['ecocontribution'] = $articleCommande->getEcocontribution();
$a['totalHt'] = -($articleCommande->getTotalHt() / $articleCommande->getQuantite() * $quantite);
$a['totalHtV2'] = -($articleCommande->getTotalHt() / $articleCommande->getQuantite() * $quantite);
/*
$serviceArticle = $this->get('dtc.article');
$quantiteSurCommande = floatval($quantiteSurCommande) + $a['quantite'];
$a['couleur']= $serviceArticle->getCouleurEtatStock($article,$quantiteSurCommande);
*
*/
$a['couleur'] = '';
//sauvegarde auto
if (is_object($articlesCommandeSource_obj) && is_object($articlesCommandeSource_obj->getCommande())) {
//modification des donnees pour l'enregistrement
if (is_object($a['article'])) {
$a['article_id'] = $a['article']->getId();
}
if (is_object($a['transporteur'])) {
$a['transporteur_id'] = $a['transporteur']->getId();
}
$a['commande_id'] = $articlesCommandeSource_obj->getCommande()->getId();
$a['libelle_secondaire'] = $a['libelleSecondaire'];
$a['frais_port'] = $a['fraisPort'];
//$a['ral_client'] = $a['ralClient'];
$a['ral_client'] = $a['quantite'];
//$a['est_commentaire'] = $a['estCommentaire'];
$a['commentaire_suppl'] = $a['commentaireSuppl'];
$a['commentaire_prive'] = $a['commentairePrive'];
$a['remise_supplementaire'] = $a['remiseSupplementaire'];
$a['total_ht'] = $a['totalHt'];
$a['tva_vente'] = -$articlesCommandeSource_obj->getTvaVente();
//$a['prix_base'] = -$a['prixBase'];
//$a['total_ht_v2'] = $a['totalHtV2'];
$a['quantite_deja_preparee'] = $a['quantiteDejaPreparee'];
$a['date'] = (new \Datetime)->format('Y-m-d H:i:s');
$a['prix_base'] = $a['prixBase'];
$a['prix_achat_unitaire_avec_frais'] = $a['prixAchatUnitaireAvecFrais'];
if (is_object($a['articleCommandeRepris'])) {
$a['article_commande_repris_id'] = $a['articleCommandeRepris']->getId();
}
//$a['prix_base'] = $a['prixBase'];
unset($a['prixBase']);
unset($a['prixAchatUnitaireAvecFrais']);
unset($a['articleCommandeRepris']);
unset($a['transporteur']);
unset($a['article']);
unset($a['commande']);
unset($a['action']);
unset($a['libelleSecondaire']);
unset($a['fraisPort']);
unset($a['quantitePrepa']);
unset($a['ralClient']);
unset($a['estCommentaire']);
unset($a['commentaireSuppl']);
unset($a['commentairePrive']);
unset($a['remiseSupplementaire']);
unset($a['totalHt']);
unset($a['totalHtV2']);
unset($a['couleur']);
unset($a['quantiteDejaPreparee']);
//print_r($a);
$conn->update('commerciale__article_commande', $a, ['id' => $articlesCommandeSource_obj->getId()]);
//$a['id'] = $conn->lastInsertId();
//$a['id'] = $conn->lastInsertId();
$a = $em->getRepository(ArticleCommande::class)->find($articlesCommandeSource_obj->getId());
$em->refresh($a);
/*
if($countTmp == 0){
$articleCommandeAssocie = $conn->lastInsertId();
} else {
//$a['articleCommandeAssocie']['id'] = $idArticleCommandeTmp;
$a->setArticleCommandeAssocie($articleCommandeAssocie);
}
*/
//reservation de stock
$commande = $articlesCommandeSource_obj->getCommande();
if (is_int($commande->getTypeDocumentCommercial()) && in_array($commande->getTypeDocumentCommercial(), [TypeDocumentCommercial::COMMANDE])) {
$type = 'commande';
$ralClientArtComm = floatval($a->getQuantite());
//$reserve = $ralClientArtComm + floatval($article->getStockReserve());
//$reserve = floatval($article->getStockReserve())-$ralClientArtComm;
if ($article->getVirtuel() == true or $article->getNonStocke() == true or $article->getNonCommandable() == true or $article->getMainOeuvre() == true) {
$article->setStockReserve(0);
if ($article->getProduitInterne() == true) {
$variation = floatval($a->getQuantite());
// $articleService->modifierStockReserveComposants($article, $variation);
}
} elseif (floatval($a->getQuantite()) != 0) {
//$article->setStockReserve($reserve);
//$em->persist($article);
}
$em->flush();
}
} else {
$a['id'] = 'tmp-'.time();
}
// TODO CHANGE THIS
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormCommande";
$type = $cible;
if ($cible == "comptoir") {
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormComptoir";
}
if ($cible == "bp") {
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormBP";
}
if ($cible == "devis") {
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormDevis";
}
if ($cible == "") {
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormCommande";
$type = "commande";
}
$colonneUtilisateur2 = $serviceColonne->getColonneUtilisateur2($colonneUtilisateur);
$tabColonneUser = $colonneUtilisateur2['tabColonneUser'];
$colspan = $colonneUtilisateur2['colspan'];
$variables = ['a' => $a, 'boucle' => "0", 'numeroLigne' => "0", 'reprise' => true, 'tabColonneUser' => $tabColonneUser, 'colspan' => $colspan, 'type' => $type];
if ($client_id != '') {
$client = $repo_client->find($client_id);
if (is_object($client)) {
$variables['client'] = $client;
}
}
//echo $cible."azertyui";
if ($cible == "or") {
$rendu = $this->renderView('GestionComerciale/ArticleCommande/template_or_tr.html.twig', $variables);
} elseif ($cible == "regularisation") {
$rendu = $this->renderView('GestionComerciale/ArticleCommande/template_regulation_tr.html.twig', $variables);
} else {
$rendu = $this->renderView('GestionComerciale/ArticleCommande/template_tr.html.twig', $variables);
}
$commentairePonctuel = $article->getCommentairePonctuel();
if ($article->getArretGamme()) {
$commentairePonctuel .= "<div>Attention article en arrêt de gamme</div>";
}
return new JsonResponse(['rendu' => $rendu, 'id' => $article->getId(), 'commentairePonctuel' => $commentairePonctuel, 'couleur' => '']);
}
public function _____construireLigneArticleCommandeRepriseAction(Request $request, ArticleCommande $articleCommande, EntityManagerInterface $em,
TranslatorInterface $translator, ValidatorInterface $validator, ColonneTableauService $serviceColonne
) {
$conn = $em->getConnection();
$conn->getConfiguration()->setSQLLogger(null);
$article = $articleCommande->getArticle();
$quantite = $request->query->get('quantite');
$quantiteSurCommande = $request->query->get('quantiteSurCommande');
$client_id = $request->query->get('client');
$cible = $request->query->get('cible');
$type = '';
$repo_client = $em->getRepository(Client::class);
if ($article->getDivers() == 1) {
$articleTmp = clone $article;
$newRef = $articleTmp->getReference().'-'.time();
$articleTmp->setReference($newRef);
$articleTmp->setParent($article);
$articleTmp->setIdImport($article->getIdImport().'-duplique');
$em->persist($articleTmp);
$em->flush();
$article = $articleTmp;
}
$a = [];
$a['commande'] = "";
$a['quantiteDejaPreparee'] = 0;
$a['action'] = "insert";
$a['position'] = 0;
$a['article'] = $article;
$a['libelle'] = $articleCommande->getLibelle();
$a['libelleSecondaire'] = $articleCommande->getLibelleSecondaire();
$a['quantite'] = -$quantite;
$a['quantitePrepa'] = -$quantite;
$a['fraisPort'] = "0";
$a['articleCommandeRepris'] = $articleCommande;
$a['transporteur'] = $articleCommande->getTransporteur();
$a['estCommentaire'] = $article->getEstCommentaire();
$commande = $articleCommande->getCommande();
$date = date_format($commande->getDate(), 'd/m/Y');
$utilisateur = $commande->getUtilisateur();
$a['commentaire'] = "Reprise sur facture n° ".$commande->getReference()." du ".$date.' saisie par '.$utilisateur->getNom().' '.$utilisateur->getPrenom();
$a['commentaireSuppl'] = "";
$a['commentairePrive'] = "";
$a['prixBase'] = $articleCommande->getPrixBase();
$a['remise'] = $articleCommande->getRemise();
$a['remiseSupplementaire'] = $articleCommande->getRemiseSupplementaire();
//$a['ecocontribution']= floatval($articleCommande->getEcocontribution());
$a['ecocontribution'] = 0;
$a['totalHt'] = $articleCommande->getTotalHt() / $articleCommande->getQuantite() * $quantite;
$a['totalHtV2'] = $articleCommande->getTotalHt() / $articleCommande->getQuantite() * $quantite;
/*
$serviceArticle = $this->get('dtc.article');
$quantiteSurCommande = floatval($quantiteSurCommande) + $a['quantite'];
$a['couleur']= $serviceArticle->getCouleurEtatStock($article,$quantiteSurCommande);
*
*/
$a['couleur'] = '';
//sauvegarde auto
if (is_object($articleCommande->getCommande())) {
//modification des donnees pour l'enregistrement
if (is_object($a['article'])) {
$a['article_id'] = $a['article']->getId();
}
if (is_object($a['transporteur'])) {
$a['transporteur_id'] = $a['transporteur']->getId();
}
$a['commande_id'] = $articleCommande->getCommande()->getId();
$a['libelle_secondaire'] = $a['libelleSecondaire'];
$a['frais_port'] = $a['fraisPort'];
//$a['ral_client'] = $a['ralClient'];
$a['ral_client'] = $a['quantite'];
//$a['est_commentaire'] = $a['estCommentaire'];
$a['commentaire_suppl'] = $a['commentaireSuppl'];
$a['commentaire_prive'] = $a['commentairePrive'];
$a['remise_supplementaire'] = $a['remiseSupplementaire'];
$a['total_ht'] = $a['totalHt'];
//$a['total_ht_v2'] = $a['totalHtV2'];
$a['quantite_deja_preparee'] = $a['quantiteDejaPreparee'];
$a['date'] = (new \Datetime)->format('Y-m-d H:i:s');
if (is_object($a['articleCommandeRepris'])) {
$a['article_commande_repris_id'] = $a['articleCommandeRepris']->getId();
}
$a['prix_base'] = $a['prixBase'];
unset($a['prixBase']);
unset($a['articleCommandeRepris']);
unset($a['transporteur']);
unset($a['article']);
unset($a['commande']);
unset($a['action']);
unset($a['libelleSecondaire']);
unset($a['fraisPort']);
unset($a['quantitePrepa']);
unset($a['ralClient']);
unset($a['estCommentaire']);
unset($a['commentaireSuppl']);
unset($a['commentairePrive']);
unset($a['remiseSupplementaire']);
unset($a['totalHt']);
unset($a['totalHtV2']);
unset($a['couleur']);
unset($a['quantiteDejaPreparee']);
$conn->update('commerciale__article_commande', $a, ['id' => $articleCommande->getId()]);
//$a['id'] = $conn->lastInsertId();
$a = $em->getRepository(ArticleCommande::class)->find($articleCommande->getId());
/*
if($countTmp == 0){
$articleCommandeAssocie = $conn->lastInsertId();
} else {
//$a['articleCommandeAssocie']['id'] = $idArticleCommandeTmp;
$a->setArticleCommandeAssocie($articleCommandeAssocie);
}
*/
//reservation de stock
if (is_int($commande->getTypeDocumentCommercial()) && in_array($commande->getTypeDocumentCommercial(), [TypeDocumentCommercial::COMMANDE])) {
$type = 'commande';
$ralClientArtComm = floatval($a->getQuantite());
$reserve = $ralClientArtComm + floatval($article->getStockReserve());
if ($article->getVirtuel() == true or $article->getNonStocke() == true or $article->getNonCommandable() == true or $article->getMainOeuvre() == true) {
$article->setStockReserve(0);
if ($article->getProduitInterne() == true) {
$variation = floatval($a->getQuantite());
$articleService->modifierStockReserveComposants($article, $variation);
}
} elseif (floatval($a->getQuantite()) != 0) {
$article->setStockReserve($reserve);
$em->persist($article);
}
$em->flush();
}
} else {
$a['id'] = 'tmp-'.time();
}
// TODO change this
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormCommande";
$type = $cible;
if ($cible == "comptoir") {
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormComptoir";
}
if ($cible == "bp") {
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormBP";
}
if ($cible == "devis") {
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormDevis";
}
if ($cible == "") {
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormCommande";
$type = "commande";
}
$colonneUtilisateur2 = $serviceColonne->getColonneUtilisateur2($colonneUtilisateur);
$tabColonneUser = $colonneUtilisateur2['tabColonneUser'];
$colspan = $colonneUtilisateur2['colspan'];
$variables = ['a' => $a, 'boucle' => "0", 'numeroLigne' => "0", 'reprise' => true, 'tabColonneUser' => $tabColonneUser, 'colspan' => $colspan, 'type' => $type];
if ($client_id != '') {
$client = $repo_client->find($client_id);
if (is_object($client)) {
$variables['client'] = $client;
}
}
//echo $cible."azertyui";
if ($cible == "or") {
$rendu = $this->renderView('GestionComerciale/ArticleCommande/template_or_tr.html.twig', $variables);
} elseif ($cible == "regularisation") {
$rendu = $this->renderView('GestionComerciale/ArticleCommande/template_regulation_tr.html.twig', $variables);
} else {
$rendu = $this->renderView('GestionComerciale/ArticleCommande/template_tr.html.twig', $variables);
}
$commentairePonctuel = $article->getCommentairePonctuel();
if ($article->getArretGamme()) {
$commentairePonctuel .= "<div>Attention article en arrêt de gamme</div>";
}
return new JsonResponse(
['rendu' => $rendu, 'id' => $article->getId(), 'commentairePonctuel' => $commentairePonctuel, 'couleur' => '']
);
}
/**
* @Route("/commande-article/recharger/{id}/{quantite}", name="dtc_recharger_ligne_article_commande")
*/
public function rechargerLigneArticleCommandeAction(Request $request, Article $article, $quantite, EntityManagerInterface $em,
ArticleService $serviceArticle
) {
$fournisseur = $request->query->get('fournisseur');
$ac = $request->query->get('idArticleCommande');
$id_client = $request->query->get('id_client');
$id_adresse = $request->query->get('id_adresse');
$prix = '';
$acObjet = '';
$client = "";
$adresse = "";
//
if ($fournisseur != '' && $fournisseur != "undefined") {
$couleur = $serviceArticle->getCouleurQteF($article, $quantite, $fournisseur);
} else {
$acObjet = $em->getRepository(ArticleCommande::class)->find($ac);
if (is_object($acObjet)) {
$commande = $acObjet->getCommande();
$couleur = $serviceArticle->getCouleurEtatStock($article, $quantite, $commande);
} else {
$couleur = $serviceArticle->getCouleurEtatStock($article, $quantite);
}
if ($id_client != "") {
$client = $em->getRepository(Client::class)->find($id_client);
}
if ($id_adresse != "") {
$adresse = $em->getRepository(Adresse::class)->find($id_adresse);
if ( ! is_object($client) && is_object($adresse)) {
$client = $adresse->getClient();
}
}
}
$prix = $serviceArticle->getPrixEncoursConditionVente($article, $acObjet, $client, $quantite, $adresse);
$rendu = "";
return new JsonResponse(['prix' => floatVal($prix), 'rendu' => $rendu, 'couleur' => $couleur, 'tutu' => $couleur]);
}
/**
* @Route("/commande-article/recharger-prix/{id}/{client}", name="dtc_recharger_prix_article_commande")
*/
public function rechargerPrixArticleCommandeAction(Request $request, Article $article, $client = '', EntityManagerInterface $em, ArticleService $serviceArticle)
{
$montantTotal = $request->query->get('montantTotal');
$prix = $request->query->get('prix');
$adresse = $request->query->get('adresse');
$quantite = $request->query->get('quantite');
$quantite = 1;
if ($client != "") {
$client = $em->getRepository(Client::class)->find($client);
}
if ($adresse != "") {
$adresse = $em->getRepository(Adresse::class)->find($adresse);
}
$a = [];
$a['quantiteDejaPreparee'] = 0;
$a['article'] = $article;
$a['libelle'] = $article->getLibelle();
$a['libelleSecondaire'] = $article->getLibelleSecondaire();
$a['commentaire'] = "";
$a['remise'] = "0";
$a['totalHt'] = $article->getPrixVente();
$a['totalHtV2'] = $article->getPrixVente();
$remise = $serviceArticle->getRemiseCategorieClient($a, $client, $montantTotal, $article->getPrixVente());
//public function getPrixEncours( $article,$articleCommande = '',$client, $reprise = false,$quantite="",$adresse="",$enregAuto =false) {
$prix = $serviceArticle->getPrixEncours($article, '', $client, false, $quantite, $adresse, false);
return new JsonResponse(['prix' => $prix, 'remise' => $remise]);
}
/**
* @Route("/commande-article/achat/commentaire/", name="dtc_construire_ligne_commentaire_commande_fournisseur")
*/
public function construireLigneCommentaireCommandeFournisseurAction(Request $request, EntityManagerInterface $em, ArticleService $serviceArticle)
{
$repo_article = $em->getRepository(Article::class);
//$article = $repo_article->findOneBy(array("est_commentaire"=>1));
$article = $repo_article->find($this->getParameter('article_commentaire'));
$repoFournisseur = $em->getRepository(Fournisseur::class);
$fournisseur = $request->query->get('fournisseur');
$commandeId = $request->query->get('commandeId');
$quantite = $request->query->get('quantite');
$a = [];
$a['id'] = 'tmp-'.time();
$a['quantiteDejaPreparee'] = 0;
$a['articleCommandeRepris'] = "";
$a['position'] = "";
$a['article'] = $article;
$a['libelle'] = $article->getLibelle();
$a['quantite'] = "1";
$a['ral'] = "1";
$a['commentaireSuppl'] = "";
$a['commentairePrive'] = "";
$a['estCommentaire'] = $article->getEstCommentaire();
$a['commentaire'] = "";
$a['remise'] = "0";
$a['remiseSupplementaire'] = "0";
//$a['ecocontribution']= floatval($article->getEcocontribution());
$a['ecocontribution'] = 0;
$a['totalHt'] = $article->getPrixBase();
$a['prixBase'] = $article->getPrixBase();
//recuperer la condition d'achat par défaut
$repoConditionsAchat = $em->getRepository(ConditionAchat::class);
//$condition = $repoConditionsAchat->findBy(array('article' => $article->getId(), 'defaut' => 1), array('id'=>'ASC'),1,0);
if ($fournisseur != '') {
$condition = $repoConditionsAchat->findOneBy([
'article' => $article->getId(),
'fournisseur' => $fournisseur,
'defaut' => 1,
]);
}
if ( ! isset($condition) || ! is_object($condition)) {
$condition = $repoConditionsAchat->findOneBy([
'article' => $article->getId(),
'fournisseur' => $fournisseur,
]);
}
/*
if(count($condition) > 0)
$condition = $condition[0];
else
$condition = $repoConditionsAchat->findOneBy(array('article' => $article->getId()));
*
*/
if (is_object($condition)) {
if ($condition->getTauxRemise() != '') {
$a['remise'] = $condition->getTauxRemise();
}
if ($condition->getTauxRemiseSupplementaire() != '') {
$a['remiseSupplementaire'] = $condition->getTauxRemiseSupplementaire();
}
if ($condition->getPrixAchatBrut() != '') {
//$a['prixBase']= $condition->getPrixAchatBrut() * $condition->getConditionnement() / $condition->getCoefficientConditionnement() ;
$a['prixBase'] = $condition->getPrixAchatBrut();
}
if ($condition->getLibelle() != '') {
$a['libelle'] = $condition->getLibelle();
}
if ($quantite != '' && is_numeric($quantite)) {
$a['quantite'] = $quantite;
} elseif ($condition->getQuantite() != '') {
$a['quantite'] = $condition->getQuantite();
}
$a['conditionAchat'] = $condition;
$a['fraisAnnexes'] = $condition->getFraisAnnexes();
}
$a['couleur'] = $serviceArticle->getCouleurEtatStock($article, $a['quantite']);
$fournisseur = $repoFournisseur->find($fournisseur);
$rendu = $this->renderView('GestionComerciale/ArticleCommande/template_tr_fournisseur.html.twig', [
'a' => $a,
'boucle' => "0",
'numeroLigne' => "0",
'fournisseur' => $fournisseur,
'commandeId' => $commandeId,
]);
return new JsonResponse(['rendu' => $rendu, 'commentairePonctuel' => $article->getCommentairePonctuel()]);
}
/**
* @Route("/commande-article/achat/nouveau/{id}", name="dtc_construire_ligne_article_commande_fournisseur")
*/
public function construireLigneArticleCommandeFournisseurAction(Request $request, Article $article, EntityManagerInterface $em, ColonneTableauService $serviceColonne,
ArticleService $articleService, DateService $dateService, FournisseurService $fournisseurService
) {
$repoFournisseur = $em->getRepository(Fournisseur::class);
$repo_taxe = $em->getRepository(Taxe::class);
$fournisseur = $request->query->get('fournisseur');
$commandeId = $request->query->get('commandeId');
$quantite = $request->query->get('quantite');
$repo_article = $em->getRepository(Article::class);
$colspan = 14;
$tabColonneUser = [];
$tabColonneUser["id"] = 1;
$tabColonneUser["reference"] = 1;
$tabColonneUser["referenceF"] = 1;
$tabColonneUser["libelle"] = 1;
$tabColonneUser["libelleF"] = 1;
$tabColonneUser["qteMini"] = 1;
$tabColonneUser["qteMaxi"] = 1;
$tabColonneUser["ralC"] = 1;
$tabColonneUser["ralF"] = 1;
$tabColonneUser["qteStockCommande"] = 1;
$tabColonneUser["uniteVente"] = 1;
$tabColonneUser["qte"] = 1;
$tabColonneUser["uniteAchat"] = 1;
$tabColonneUser["prixAchatUnitaire"] = 1;
$tabColonneUser["prixHT"] = 1;
$tabColonneUser["CC"] = 1;
$tabColonneUser["qteMiniAchat"] = 1;
$tabColonneUser["conditionnement"] = 1;
$tabColonneUser["txRem"] = 1;
$tabColonneUser["txRemSuppl"] = 1;
$tabColonneUser["fraisAnnexes"] = 1;
$tabColonneUser["ecocontribution"] = 1;
$tabColonneUser["montantHt"] = 1;
$tabColonneUser["totalHT"] = 1;
$tabColonneUser["pump"] = 1;
$tabColonneUser["stock"] = 1;
$tabColonneUser["dateApproximativeReception"] = 1;
$tabColonneUser["emplacement"] = 1;
// TODO CHANGE THIS
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormCommandeFournisseur";
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'id') == false) {
$colspan--;
$tabColonneUser["id"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'reference') == false) {
$colspan--;
$tabColonneUser["reference"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'referenceF') == false) {
$colspan--;
$tabColonneUser["referenceF"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'libelle') == false) {
$colspan--;
$tabColonneUser["libelle"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'libelleF') == false) {
$colspan--;
$tabColonneUser["libelleF"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'qteMini') == false) {
$colspan--;
$tabColonneUser["qteMini"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'qteMaxi') == false) {
$colspan--;
$tabColonneUser["qteMaxi"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'ralC') == false) {
$colspan--;
$tabColonneUser["ralC"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'ralF') == false) {
$colspan--;
$tabColonneUser["ralF"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'qteStockCommande') == false) {
$colspan--;
$tabColonneUser["qteStockCommande"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'uniteVente') == false) {
$colspan--;
$tabColonneUser["uniteVente"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'qte') == false) {
$colspan--;
$tabColonneUser["qte"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'uniteAchat') == false) {
$colspan--;
$tabColonneUser["uniteAchat"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'prixAchatUnitaire') == false) {
$colspan--;
$tabColonneUser["prixAchatUnitaire"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'prixHT') == false) {
$colspan--;
$tabColonneUser["prixHT"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'CC') == false) {
$colspan--;
$tabColonneUser["CC"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'qteMiniAchat') == false) {
$colspan--;
$tabColonneUser["qteMiniAchat"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'conditionnement') == false) {
$colspan--;
$tabColonneUser["conditionnement"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'txRem') == false) {
$colspan--;
$tabColonneUser["txRem"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'txRemSuppl') == false) {
$colspan--;
$tabColonneUser["txRemSuppl"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'fraisAnnexes') == false) {
$colspan--;
$tabColonneUser["fraisAnnexes"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'ecocontribution') == false) {
$colspan--;
$tabColonneUser["ecocontribution"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'montantHt') == false) {
$colspan--;
$tabColonneUser["montantHt"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'totalHT') == false) {
$colspan--;
$tabColonneUser["totalHT"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'pump') == false) {
$colspan--;
$tabColonneUser["pump"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'stock') == false) {
$colspan--;
$tabColonneUser["stock"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'dateApproximativeReception') == false) {
$colspan--;
$tabColonneUser["dateApproximativeReception"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'emplacement') == false) {
$colspan--;
$tabColonneUser["emplacement"] = 0;
}
$conn = $em->getConnection();
$conn->getConfiguration()->setSQLLogger(null);
$rendu = '';
$commentairePonctuel = '';
$articles = [$article];
if (is_object($article->getArticleEnconsigne())) {
$articles[] = $article->getArticleEnconsigne();
}
foreach ($articles as $article) {
if ($article->getDivers() == 1 && ! is_object($article->getParent())) {
/*
$articleTmp = clone $article;
$newRef = $articleTmp->getReference().'-'.time();
$articleTmp->setReference($newRef);
$articleTmp->setParent($article);
$articleTmp->setIdImport($article->getIdImport().'-duplique');
$em->persist($articleTmp);
$em->flush();
$article = $articleTmp;
*/
$referenceDivers = $articleService->getReferenceDivers($article);
$tableau_donnee = [];
$tableau_donnee["reference"] = $article->getReference()."-".$referenceDivers['reference'];
$tableau_donnee["numero_reference"] = $referenceDivers['numero_reference'];
$tableau_donnee["ral_fournisseur"] = "0";
$tableau_donnee["parent_id"] = $article->getId();
$tableau_donnee["libelle"] = $article->getLibelle();
$tableau_donnee["reference_client"] = $article->getReferenceClient();
$tableau_donnee["reference_fournisseur"] = $article->getReferenceFournisseur();
$tableau_donnee["prix_base"] = $article->getPrixBase();
$dateTmp = new \Datetime;
$tableau_donnee["date"] = $dateTmp->format("Y-m-d H:i:s");
if ($article->getDateMaj() != "") {
$tableau_donnee["date_maj"] = $article->getDateMaj()->format("Y-m-d H:i:s");
}
if ($article->getDateMajPrix() != "") {
$tableau_donnee["date_maj_prix"] = $article->getDateMajPrix()->format("Y-m-d H:i:s");
}
if ($article->getDateSuppression() != "") {
$tableau_donnee["date_supression"] = $article->getDateSuppression()->format("Y-m-d H:i:s");
}
if (is_object($article->getMarque())) {
$tableau_donnee["marque_id"] = $article->getMarque()->getId();
}
$tableau_donnee["description"] = $article->getDescription();
$tableau_donnee["description_courte"] = $article->getDescriptionCourte();
$tableau_donnee["stock"] = "0";
if ($article->getStatut() === true) {
$tableau_donnee["statut"] = 1;
} else {
$tableau_donnee["statut"] = 0;
}
$tableau_donnee["largeur"] = $article->getLargeur();
$tableau_donnee["profondeur"] = $article->getProfondeur();
$tableau_donnee["hauteur"] = $article->getHauteur();
$tableau_donnee["poids"] = $article->getPoids();
if ($article->getAConsigner()) {
$tableau_donnee["a_consigner"] = 1;
} else {
$tableau_donnee["a_consigner"] = 0;
}
if ($article->getStockAuto()) {
$tableau_donnee["stock_auto"] = 1;
} else {
$tableau_donnee["stock_auto"] = 0;
}
if ($article->getArretGamme() === true) {
$tableau_donnee["arret_gamme"] = 1;
} else {
$tableau_donnee["arret_gamme"] = 0;
}
if (is_object($article->getUtilisateur())) {
$tableau_donnee["utilisateur_id"] = $article->getUtilisateur()->getId();
}
if (is_object($article->getRegleTaxe())) {
$tableau_donnee["regle_taxe_id"] = $article->getRegleTaxe()->getId();
}
$tableau_donnee["remise_max"] = $article->getRemiseMax();
$tableau_donnee["type_remise_max"] = $article->getTypeRemiseMax();
$tableau_donnee["seuil_commande_f_mini"] = $article->getSeuilMiniCommandeFournisseur();
$tableau_donnee["seuil_commande_f_maxi"] = $article->getSeuilMaxiCommandeFournisseur();
if (is_object($article->getNiveauUn())) {
$tableau_donnee["niveau_un_id"] = $article->getNiveauUn()->getId();
}
if (is_object($article->getNiveauDeux())) {
$tableau_donnee["niveau_deux_id"] = $article->getNiveauDeux()->getId();
}
if (is_object($article->getNiveauTrois())) {
$tableau_donnee["niveau_trois_id"] = $article->getNiveauTrois()->getId();
}
if (is_object($article->getNiveauQuatre())) {
$tableau_donnee["niveau_quatre_id"] = $article->getNiveauQuatre()->getId();
}
$tableau_donnee["pump"] = $article->getCpump();
$tableau_donnee["commentaire"] = $article->getCommentairePonctuel();
if ($article->getVirtuel()) {
$tableau_donnee["virtuel"] = 1;
} else {
$tableau_donnee["virtuel"] = 0;
}
//$tableau_donnee["prix_vente"]=$article->getLibelle();
$tableau_donnee["prix_vente"] = 0;
$tableau_donnee["taux_marge"] = $article->getTauxMarge();
$tableau_donnee["marge"] = $article->getMarge();
$tableau_donnee["marge_reelle"] = $article->getMargeReelle();
$tableau_donnee["ecotaxe"] = $article->getEcotaxe();
$tableau_donnee["conditionnement"] = $article->getConditionnement();
$tableau_donnee["stock_reserve"] = $article->getStockReserve();
if (is_object($article->getFournisseurDefaut())) {
$tableau_donnee["fournisseur_defaut_id"] = $article->getFournisseurDefaut()->getId();
}
$tableau_donnee["ral_fournisseur"] = "0";
$tableau_donnee["id_import"] = "";
$tableau_donnee["donnees_import"] = "";
if ($article->getMajPrix()) {
$tableau_donnee["maj_prix"] = 1;
} else {
$tableau_donnee["maj_prix"] = 0;
}
if (is_object($article->getUniteMesure())) {
$tableau_donnee["unite_mesure_id"] = $article->getUniteMesure()->getId();
}
if ($article->getAfficherComposantPdfInterne()) {
$tableau_donnee["afficher_composant_pdf_interne"] = 1;
} else {
$tableau_donnee["afficher_composant_pdf_interne"] = 0;
}
if ($article->getAfficherComposantPdfExterne()) {
$tableau_donnee["afficher_composant_pdf_externe"] = 1;
} else {
$tableau_donnee["afficher_composant_pdf_externe"] = 0;
}
if (is_object($article->getCategorieRemiseArticle())) {
$tableau_donnee["categorie_remise_article_id"] = $article->getCategorieRemiseArticle()->getId();
}
$tableau_donnee["temporaire"] = $article->getTemporaire();
$tableau_donnee["libelle_secondaire"] = $article->getLibelleSecondaire();
$tableau_donnee["a_commander"] = "1";
$tableau_donnee["a_fabriquer"] = "0";
$tableau_donnee["quantite_conseillee_mini"] = $article->getQuantiteConseilleeMini();
$tableau_donnee["quantite_conseillee"] = $article->getQuantiteConseillee();
$tableau_donnee["quantite_conseillee_maxi"] = $article->getQuantiteConseilleeMaxi();
if ($article->getArchive() === true) {
$tableau_donnee["archive"] = 1;
} else {
$tableau_donnee["archive"] = 0;
}
$tableau_donnee["coefficient_px_base_px_vente"] = $article->getCoefficientPrixBaseVente();
$tableau_donnee["nom_web"] = $article->getNomWeb();
$tableau_donnee["reference_web"] = $article->getReferenceWeb();
$tableau_donnee["reference_fournisseur_web"] = $article->getReferenceFournisseurWeb();
$tableau_donnee["description_web"] = $article->getDescriptionWeb();
$tableau_donnee["resume_web"] = $article->getResumeWeb();
$tableau_donnee["frais_ports_texte_web"] = $article->getFraisPortsTexteWeb();
$tableau_donnee["message_qd_en_stock"] = $article->getMessageQdEnStockWeb();
if (is_object($article->getArticleEnconsigne())) {
$tableau_donnee["article_enconsigne_id"] = $article->getArticleEnconsigne()->getId();
}
$tableau_donnee["reference_appel_1"] = $article->getReferenceAppel1();
$tableau_donnee["reference_appel_2"] = $article->getReferenceAppel2();
$tableau_donnee["reference_appel_3"] = $article->getReferenceAppel3();
$tableau_donnee["reference_appel_4"] = $article->getReferenceAppel4();
$tableau_donnee["reference_appel_5"] = $article->getReferenceAppel5();
$tableau_donnee["reference_appel_6"] = $article->getReferenceAppel6();
$tableau_donnee["reference_appel_7"] = $article->getReferenceAppel7();
$tableau_donnee["reference_appel_8"] = $article->getReferenceAppel8();
$tableau_donnee["reference_appel_9"] = $article->getReferenceAppel9();
$tableau_donnee["reference_appel_10"] = $article->getReferenceAppel10();
$tableau_donnee["reference_appel_11"] = $article->getReferenceAppel11();
if ($article->getMainOeuvre() === true) {
$tableau_donnee["main_oeuvre"] = 1;
} else {
$tableau_donnee["main_oeuvre"] = 0;
}
$tableau_donnee["stock_reserve_fabrication"] = $article->getStockReserveFabrication();
if (is_object($article->getType())) {
$tableau_donnee["type_id"] = $article->getType()->getId();
}
if (is_object($article->getFamilleCompta())) {
$tableau_donnee["famille_compta_id"] = $article->getFamilleCompta()->getId();
}
if ($article->getPrestation()) {
$tableau_donnee["prestation"] = 1;
} else {
$tableau_donnee["prestation"] = 0;
}
if ($article->getNonStocke() === true) {
$tableau_donnee["non_stocke"] = 1;
} else {
$tableau_donnee["non_stocke"] = 0;
}
if ($article->getNonCommandable()) {
$tableau_donnee["non_commandable"] = 1;
} else {
$tableau_donnee["non_commandable"] = 0;
}
if (is_object($article->getParent())) {
$tableau_donnee["parent_id"] = $article->getParent()->getId();
}
$tableau_donnee["divers"] = $article->getDivers();
if ($article->getMouvemente() === true) {
$tableau_donnee["mouvemente"] = 1;
} else {
$tableau_donnee["mouvemente"] = 0;
}
if ($article->getNumSerieObligatoire()) {
$tableau_donnee["num_serie_obligatoire"] = 1;
} else {
$tableau_donnee["num_serie_obligatoire"] = 0;
}
if (is_object($article->getArticleRemplacement())) {
$tableau_donnee["article_remplacement_id"] = $article->getArticleRemplacement()->getId();
}
if ($article->getMajPoids()) {
$tableau_donnee["maj_poids"] = 1;
} else {
$tableau_donnee["maj_poids"] = 0;
}
if ($article->getMajPrixBase()) {
$tableau_donnee["maj_prix_base"] = 1;
} else {
$tableau_donnee["maj_prix_base"] = 0;
}
if ($article->getEstCommentaire()) {
$tableau_donnee["est_commentaire"] = 1;
} else {
$tableau_donnee["est_commentaire"] = 0;
}
$tableau_donnee["cond_achat"] = $article->getConditionnementAchat();
$tableau_donnee["seuil_critique"] = $article->getSeuilCritique();
if (is_object($article->getRegleTaxeAchat())) {
$tableau_donnee["regle_taxe_achat_id"] = $article->getRegleTaxeAchat()->getId();
}
$tableau_donnee["maj_prix"] = 1;
$conn->insert('article__article', $tableau_donnee);
$idNouveauArticle = $conn->lastInsertId();
$article = $repo_article->find($idNouveauArticle);
}
$a = [];
$a['id'] = 'tmp-'.time();
$a['position'] = "";
$a['article'] = $article;
$a['ecocontribution'] = floatval($article->getEcocontribution());
$a['libelle'] = $article->getLibelle();
if ($quantite != '' && is_numeric($quantite)) {
$a['quantite'] = $quantite;
$a['ral'] = $quantite;
} else {
$a['quantite'] = "1";
$a['ral'] = "1";
}
//$a['estCommentaire']=$article->getEstCommentaire();
if ($article->getEstCommentaire()) {
$a['estCommentaire'] = 1;
} else {
$a['estCommentaire'] = 0;
}
$a['commentaire'] = "";
$a['commentaireSuppl'] = "";
$a['commentairePrive'] = "";
$a['remise'] = "0";
$a['remiseSupplementaire'] = "0";
$a['totalHt'] = $article->getPrixBase();
$a['prixBase'] = $article->getPrixBase();
$condition = '';
//recuperer la condition d'achat par défaut
$repoConditionsAchat = $em->getRepository(ConditionAchat::class);
//$condition = $repoConditionsAchat->findBy(array('article' => $article->getId(), 'defaut' => 1), array('id'=>'ASC'),1,0);
if ($fournisseur != '') {
$condition = $repoConditionsAchat->findOneBy([
'article' => $article->getId(),
'fournisseur' => $fournisseur,
'defaut' => 1,
]);
}
if ( ! isset($condition) || ! is_object($condition)) {
/*
$condition = $repoConditionsAchat->findOneBy(array('article' => $article->getId(),
'fournisseur' => $fournisseur,
));
*/
$conditions = $repoConditionsAchat->findBy(['article' => $article->getId(), 'fournisseur' => $fournisseur,], ['quantite' => 'ASC'], 1, 0);
if (count($conditions)) {
$condition = $conditions[0];
}
}
/*
if(count($condition) > 0)
$condition = $condition[0];
else
$condition = $repoConditionsAchat->findOneBy(array('article' => $article->getId()));
*
*/
$a['coefficientConditionnement'] = 1;
$a['fraisAnnexes'] = 0;
$a['dateApproximativeReception'] = null;
if (is_object($condition)) {
$a['coefficientConditionnement'] = $condition->getCoefficientConditionnement();
if ($condition->getPrixNet()) {
$a['remise'] = "0";
$a['remiseSupplementaire'] = "0";
if ($condition->getPrixAchatNet() != '') {
//$a['prixBase']= $condition->getPrixAchatBrut() * $condition->getConditionnement() / $condition->getCoefficientConditionnement() ;
$a['prixBase'] = $condition->getPrixAchatNet();
}
} else {
if ($condition->getTauxRemise() != '') {
$a['remise'] = $condition->getTauxRemise();
}
if ($condition->getTauxRemiseSupplementaire() != '') {
$a['remiseSupplementaire'] = $condition->getTauxRemiseSupplementaire();
}
if ($condition->getPrixAchatBrut() != '') {
//$a['prixBase']= $condition->getPrixAchatBrut() * $condition->getConditionnement() / $condition->getCoefficientConditionnement() ;
$a['prixBase'] = $condition->getPrixAchatBrut();
}
}
if ($condition->getLibelle() != '') {
$a['libelle'] = $condition->getLibelle();
}
if ($quantite != '' && is_numeric($quantite)) {
$a['quantite'] = $quantite;
} elseif ($condition->getQuantite() != '') {
//$a['quantite']=$condition->getQuantite();
$conditionnement = 1;
if ($condition->getConditionnement() != '') {
$conditionnement = floatval($condition->getConditionnement());
}
$quantite = floatval($condition->getQuantite());
$i = 1;
while ($quantite % $conditionnement != 0) {
$quantite++;
}
$a['quantite'] = $quantite;
$a['ral'] = $quantite;
$a['referenceFournisseur'] = $condition->getReferenceFournisseur();
}
$a['conditionAchat'] = $condition;
$a['fraisAnnexes'] = $condition->getFraisAnnexes();
if (floatval($condition->getDelai()) > 0) {
$joursLivraison = ["lundi", "mardi", "mercredi", "jeudi", "vendredi"];
$dateLivraisonTheorique = $dateService->date_addWorkingDays(strtotime((new \Datetime)->format("Y-m-d")), floatval($condition->getDelai()), $joursLivraison);
//$a['dateApproximativeReception'] = (new \Datetime)->modify('+ '.floatval($condition->getDelai()).' days');
$a['dateApproximativeReception'] = $dateLivraisonTheorique;
}
} else {
continue;
}
$a['couleur'] = $articleService->getCouleurEtatStock($article, $a['quantite']);
$fournisseur = $repoFournisseur->find($fournisseur);
$taxe = $repo_taxe->find(5);
if (is_object($fournisseur)) {
$taxe = $fournisseurService->getTaxe($fournisseur, $article);
}
$a['tva'] = $taxe->getTaux();
$a['taxe'] = $taxe;
$a['prixAchatUnitaireAvecFrais'] = $a['prixBase'];
$commentairePonctuel .= $article->getCommentairePonctuel().'<br>';
$rendu .= $this->render('GestionComerciale/ArticleCommande/template_tr_fournisseur.html.twig', [
'a' => $a,
'boucle' => "0",
'numeroLigne' => "0",
'fournisseur' => $fournisseur,
'commandeId' => $commandeId,
'tabColonneUser' => $tabColonneUser,
]);
}
/*
$rendu = $this->renderView('GestionComerciale/ArticleCommande/template_tr_fournisseur.html.twig', array(
'a'=>$a,
'boucle'=>"0",
'numeroLigne'=>"0",
'fournisseur'=>$fournisseur,
'commandeId' => $commandeId,
'tabColonneUser' => $tabColonneUser
));
*/
return new JsonResponse(['rendu' => $rendu, 'commentairePonctuel' => $commentairePonctuel]);
}
/**
* @Route("/commande-article/achat/condition-achat/{id}", name="dtc_condition_achat_commande_fournisseur")
*/
public function conditionAchatCommandeFournisseurAction(Request $request, Article $article, EntityManagerInterface $em, ArticleService $articleService
) {
$fournisseur = $request->query->get('fournisseur');
$commandeFournisseur = $request->query->get('commandeFournisseur');
$repoConditionsAchat = $em->getRepository(ConditionAchat::class);
$conditions = $repoConditionsAchat->findBy(['article' => $article->getId(), 'fournisseur' => $fournisseur]);
$repoArticleCommande = $em->getRepository(ArticleCommande::class);
$ralFourn = $repoArticleCommande->getRalFournisseur($article);
$retour = $articleService->getQteConseillee($article);
$quantiteMin = $retour['qteMini'];
$quantiteMax = $retour['qteMaxi'];
$quantite = $request->query->get('quantite');
$retours = [];
foreach ($conditions as $condition) {
$qteConseillee = $articleService->getQteConseillee($article, $condition);
$retour = [];
$retour['quantite'] = $qteConseillee['qteConseillee'];
$retour['id'] = $condition->getId();
$retour['quantiteCond'] = $condition->getQuantite();
$retour['prixAchatBrut'] = $condition->getPrixAchatBrut();
$retour['tauxRemise'] = $condition->getTauxRemise();
$retour['tauxRemiseSupplementaire'] = $condition->getTauxRemiseSupplementaire();
$retour['defaut'] = $condition->getDefaut();
$retour['conditionnement'] = $condition->getConditionnement();
$retour['quantiteMin'] = $qteConseillee['qteMini'];
$retour['quantiteMax'] = $qteConseillee['qteMaxi'];
//$retour['reference'] = $article->getReference().' / '.$condition->getReferenceFournisseur();
$retour['reference'] = $article->getReference();
$retour['coefficientConditionnement'] = $condition->getCoefficientConditionnement();
$retour['fraisAnnexes'] = $condition->getFraisAnnexes();
$retour['condition'] = $condition;
$retours[] = $retour;
}
//print_r($retour);
$titreModal = 'Conditions d\'achat';
$rendu = $this->renderView('GestionComerciale/ArticleCommande/condition_achat.html.twig', [
'conditions' => $retours,
'article' => $article,
'quantite' => $quantite,
//'quantiteMin'=>$quantiteMin,
//'quantiteMax'=>$quantiteMax,
'ralFournisseur' => $ralFourn,
'cond' => $request->query->get('cond'),
'commandeFournisseur' => $commandeFournisseur,
]);
return new JsonResponse(['rendu' => $rendu, 'titre' => $titreModal]);
}
/**
* @Route("/conditions-achat/article/{id}", name="dtc_condition_achat_article")
*/
public function conditionAchatArticleAction(Request $request, Article $article, EntityManagerInterface $em, ArticleService $articleService
) {
$repoConditionsAchat = $em->getRepository(ConditionAchat::class);
$conditions = $repoConditionsAchat->findBy(['article' => $article->getId()]);
$repoArticleCommande = $em->getRepository(ArticleCommande::class);
$ralFourn = $repoArticleCommande->getRalFournisseur($article);
$retour = $articleService->getQteConseillee($article);
$quantiteMin = $retour['qteMini'];
$quantiteMax = $retour['qteMaxi'];
$quantite = $request->query->get('quantite');
$retours = [];
foreach ($conditions as $condition) {
$qteConseillee = $articleService->getQteConseillee($article, $condition);
$retour = [];
$retour['quantite'] = $qteConseillee['qteConseillee'];
$retour['id'] = $condition->getId();
$retour['quantiteCond'] = $condition->getQuantite();
$retour['prixAchatBrut'] = $condition->getPrixAchatBrut();
$retour['tauxRemise'] = $condition->getTauxRemise();
$retour['tauxRemiseSupplementaire'] = $condition->getTauxRemiseSupplementaire();
$retour['defaut'] = $condition->getDefaut();
$retour['conditionnement'] = $condition->getConditionnement();
$retour['quantiteConseillee'] = $qteConseillee['qteConseillee'];
$retour['quantiteMin'] = $qteConseillee['qteMini'];
$retour['quantiteMax'] = $qteConseillee['qteMaxi'];
$retour['reference'] = $article->getReference().' / '.$condition->getReferenceFournisseur();
$retour['coefficientConditionnement'] = $condition->getCoefficientConditionnement();
$retour['fraisAnnexes'] = $condition->getFraisAnnexes();
$retour['condition'] = $condition;
$retours[] = $retour;
}
//print_r($retour);
$titreModal = 'Conditions d\'achat';
$rendu = $this->renderView('Articles/ConditionAchat/conditions-achat-article-modal.html.twig', [
'conditions' => $retours,
'article' => $article,
'ralFournisseur' => $ralFourn,
'quantite' => $quantite,
]);
return new JsonResponse(['rendu' => $rendu, 'titre' => $titreModal]);
}
/**
* @Route("/commande/facturable/verifier", name="dtc_commande_facturable")
*/
public function verifierCommandeFacturableAction(Request $request, EntityManagerInterface $em, CommandeService $commandeService)
{
$infos = '';
$repo_commande = $em->getRepository(Commande::class);
$repo_article_commande = $em->getRepository(ArticleCommande::class);
$commande = $repo_commande->find($request->query->get('id_commande'));
$articlesCommandeIds = $request->query->get('articlesCommandeIds');
$qtes = $request->query->get('qte');
//modifier les quantités
/*
$commandeAtester = new Commande;
$commandeAtester->setTypeDocumentCommercial($commande->getTypeDocumentCommercial());
*
*/
foreach ($commande->getArticleCommande() as $articleCommande) {
$commande->removeArticleCommande($articleCommande);
}
foreach ($articlesCommandeIds as $key => $articleCommandeId) {
$articleCommande = $repo_article_commande->find($articleCommandeId);
$articleCommandeClone = clone $articleCommande;
$articleCommandeClone->setQuantite($qtes[$key]);
$commande->addArticleCommande($articleCommandeClone);
$infos = $qtes[$key];
}
$data = $commandeService->estFacturable($commande);
return new JsonResponse(['data' => $data, 'infos' => $infos]);
}
/**
* @Route("/client/{id}/facturable/verifier", name="dtc_client_facturable")
*/
public function verifierClientFacturableAction(Request $request, Client $client)
{
$infos = '';
//$repo_client = $em->getRepository('DTCClientsBundle:Client');
//$serviceCommande = $this->get('dtc.commande');
//$data = $serviceCommande->estFacturable($commande);
/*
if(is_object($client->getModeReglement()) && $client->getModeReglement()->getId() == 6)
$facturable = 'false';
else
$facturable = 'true';
*
*/
if ($client->getFacturationMultiBL() == false) {
$facturable = 'true';
} else {
$facturable = 'false';
}
return new JsonResponse(['facturable' => $facturable, 'infos' => $infos]);
}
/**
* @Route("/compte-bancaire/{id}/recharger", name="dtc_recharger_infos_bancaires")
*/
public function rechargerInfosBancairesAction(Request $request, $id, EntityManagerInterface $em)
{
$compteBancaire = $em->getRepository(CompteBancaire::class)->getInfos($id);
return new JsonResponse(['compteBancaire' => $compteBancaire]);
}
/**
* @Route("/facture-article/achat/nouveau/{id}", name="dtc_construire_ligne_article_facture_fournisseur")
*/
public function construireLigneArticleFactureFournisseurAction(Request $request, Article $article, EntityManagerInterface $em, ArticleService $serviceArticle,
FournisseurService $fournisseurService
) {
$fournisseur = $request->query->get('fournisseur');
$quantite = $request->query->get('quantite');
$a = [];
$a['quantiteDejaPreparee'] = 0;
$a['commandeFournisseur'] = $request->query->get('commandeFournisseur');
$a['majCondAchat'] = '';
$a['position'] = "";
$a['fraisAnnexes'] = 0;
$a['ecocontribution'] = floatval($article->getEcocontribution());
$a['article'] = $article;
$a['libelle'] = $article->getLibelle();
if ($quantite != '' && is_numeric($quantite)) {
$a['quantite'] = $quantite;
$a['ral'] = $quantite;
} else {
$a['quantite'] = "1";
$a['ral'] = "1";
}
$a['commentaire'] = "";
$a['remise'] = "0";
$a['remiseSupplementaire'] = "0";
$a['totalHt'] = $article->getPrixBase();
$a['prixBase'] = $article->getPrixBase();
//recuperer la condition d'achat par défaut
$repoConditionsAchat = $em->getRepository(ConditionAchat::class);
//$condition = $repoConditionsAchat->findBy(array('article' => $article->getId(), 'defaut' => 1), array('id'=>'ASC'),1,0);
if ($fournisseur != '') {
$condition = $repoConditionsAchat->findOneBy([
'article' => $article->getId(),
'fournisseur' => $fournisseur,
'defaut' => 1,
]);
}
if ( ! isset($condition) || ! is_object($condition)) {
$condition = $repoConditionsAchat->findOneBy([
'article' => $article->getId(),
'fournisseur' => $fournisseur,
]);
}
/*
if(count($condition) > 0)
$condition = $condition[0];
else
$condition = $repoConditionsAchat->findOneBy(array('article' => $article->getId()));
*
*/
$a['coefficientConditionnement'] = 1;
if (is_object($condition)) {
if ($condition->getTauxRemise() != '') {
$a['remise'] = $condition->getTauxRemise();
}
if ($condition->getTauxRemiseSupplementaire() != '') {
$a['remiseSupplementaire'] = $condition->getTauxRemiseSupplementaire();
}
if ($condition->getPrixAchatNet() != '') {
$a['prixBase'] = $condition->getPrixAchatNet();
}
if ($condition->getLibelle() != '') {
$a['libelle'] = $condition->getLibelle();
}
if ($condition->getfraisAnnexes() != '') {
$a['fraisAnnexes'] = $condition->getfraisAnnexes();
}
if ($quantite != '' && is_numeric($quantite)) {
$a['quantite'] = $quantite;
} elseif ($condition->getQuantite() != '') {
$a['quantite'] = $condition->getQuantite();
}
if ($condition->getCoefficientConditionnement() != '') {
$a['coefficientConditionnement'] = $condition->getCoefficientConditionnement();
}
}
$a['couleur'] = $serviceArticle->getCouleurEtatStock($article, $a['quantite']);
$repo_fournisseur = $em->getRepository(Fournisseur::class);
$fournisseur = $repo_fournisseur->find($fournisseur);
$repo_taxe = $em->getRepository(Taxe::class);
$taxes = $repo_taxe->findAll();
$taxe = $repo_taxe->find(5);
if (is_object($fournisseur)) {
$taxe = $fournisseurService->getTaxe($fournisseur, $article);
}
if (is_object($taxe)) {
$a['taxe'] = $taxe;
}
$rendu = $this->renderView(
'GestionComerciale/ArticleCommande/template_tr_facture_fournisseur.html.twig',
['a' => $a, 'boucle' => "0", 'numeroLigne' => "0", 'fournisseur' => $fournisseur, 'taxes' => $taxes]
);
return new JsonResponse(['rendu' => $rendu, 'commentairePonctuel' => $article->getCommentairePonctuel()]);
}
/**
* @Route("/fabrication-multiple/fabrication/ajouter/{id}", name="dtc_construire_ligne_fabrication_multiple")
*/
public function construireLigneFabricationMultipleAction(Request $request, $id, EntityManagerInterface $em, ArticleService $articleService)
{
$date = new \DateTime();
//$quantite = $request->query->get('quantite');
$repoArticle = $em->getRepository(Article::class);
$article = $repoArticle->find($id);
$quantite = $repoArticle->getQuantiteAFabriquer($article);
$quantite = $articleService->quantiteAfabriquer($article);
$fabrication = new Fabrication();
$fabrication->setArticle($article);
$fabrication->setDate($date);
$fabrication->setQuantite($quantite);
$em->persist($fabrication);
$em->flush();
$hide = $request->query->get('hide');
$cump = $articleService->getCumpFabrication3($article, true, $quantite);
$trFabrication = $this->renderView('GestionComerciale/FabricationMultiple/table-compose-tr.html.twig', ['fabrication' => $fabrication, 'cumpTmp' => $cump]);
$jsFabrication = $this->renderView('GestionComerciale/FabricationMultiple/table-compose-js.html.twig', ['fabrication' => $fabrication]);
$detailFabrication = $this->renderView('GestionComerciale/FabricationMultiple/detail-fabrication.html.twig', ['fabrication' => $fabrication, 'hide' => $hide]);
return new Response(json_encode(['trFabrication' => $trFabrication, 'jsFabrication' => $jsFabrication, 'detailFabrication' => $detailFabrication]));
}
/**
* @Route("/charger-dernier-prix/article/{article}/client/{client}/quantite/{quantite}", name="dtc_charger_dernier_prix")
*/
public function chargerDernierPrixAction(Request $request, $article, $client, $quantite, EntityManagerInterface $em)
{
$repo_article = $em->getRepository(Article::class);
$objet = $repo_article->find($article);
$get = $request->query->all();
$articleCommandeSource = "";
if ( ! empty($get["articleCommandeId"])) {
$articleCommandeSource = $get["articleCommandeId"];
}
$repoArticleCommande = $em->getRepository(ArticleCommande::class);
$articlesCommande = $repoArticleCommande->chargerDernierPrix($article, $client)->getQuery()->getResult();
$retour = $this->renderView('GestionComerciale/ArticleCommande/liste-dernieres-ventes.html.twig', [
'articlesCommande' => $articlesCommande,
'articlesCommandeSource' => $articleCommandeSource,
'quantite' => $quantite,
]);
$titre = "Dernières factures du produit : ".$objet->getReference();
return new JsonResponse(['retour' => $retour, 'titre' => $titre]);
}
/**
* @Route("/charger-dernier-prix-fournisseur/article/{article}/fournisseur/{fournisseur}/quantite/{quantite}", name="dtc_charger_dernier_prix_fournisseur")
*/
public function chargerDernierPrixFournisseurAction(Request $request, $article, $fournisseur, $quantite, EntityManagerInterface $em)
{
$repo_article = $em->getRepository(Article::class);
$objet = $repo_article->find($article);
$get = $request->query->all();
$articleCommandeSource = "";
if ( ! empty($get["articleCommandeId"])) {
$articleCommandeSource = $get["articleCommandeId"];
}
$repoArticleCommande = $em->getRepository(ArticleCommande::class);
$articlesCommande = $repoArticleCommande->chargerDernierPrixFournisseur($article, $fournisseur)->getQuery()->getResult();
$retour = $this->renderView('GestionComerciale/ArticleCommande/liste-dernieres-ventes-fournisseur.html.twig', [
'articlesCommande' => $articlesCommande,
'articlesCommandeSource' => $articleCommandeSource,
'quantite' => $quantite,
]);
$titre = "Dernières factures du produit : ".$objet->getReference();
return new JsonResponse(['retour' => $retour, 'titre' => $titre]);
}
/**
* @Route("/commande-fournisseur/recharger-total-article/{articleId}", name="dtc_total_prestation")
*/
public function getTotalPrestationAction(Request $request, $articlePrestation = '', $fabrications = [], EntityManagerInterface $em)
{
$repo_fabrication = $em->getRepository(Fabrication::class);
$donnees = [];
$donnees['quantitePrestation'] = 0;
$fabrications = $request->query->get('fabrications');
if (count($fabrications) > 0) {
foreach ($fabrications as $fabricationId) {
$fabrication = $repo_fabrication->find($fabricationId);
if (is_object($fabrication)) {
$donnees['quantitePrestation'] += $fabrication->getQuantitePrestation();
}
}
}
return new JsonResponse(['retour' => $donnees]);
}
/**
* @Route("/commande/{id}/commandes/modifier/client/{idClient}", name="dtc_ajax_get_commande_a_modifier")
*/
public function getCommandesModifierClientAction(Request $request, Commande $commande, $idClient, EntityManagerInterface $em)
{
$donnees = [];
$routes = [];
$route = 'dtc_commande_modifier';
$hasAcomptes = 'false';
$repo_commande = $em->getRepository(Commande::class);
$commandes = $repo_commande->getDocumentClientAmodifier($commande)->getQuery()->getResult();
if (is_object($commande->getClient()) && $commande->getClient()->getId() != $idClient) {
$repo_client = $em->getRepository(Client::class);
$client_obj = $repo_client->find($idClient);
if (is_object($client_obj)) {
$commande->setClient($client_obj);
$em->persist($commande);
$em->flush();
}
}
if (count($commandes) > 0) {
$hasAcomptes = 'false';
foreach ($commandes as $commande) {
if ($commande->getClient()->getId() != $idClient) {
$route = 'dtc_commande_modifier';
if (is_int($commande->getTypeDocumentCommercial())) {
$typeDocId = $commande->getTypeDocumentCommercial();
switch ($typeDocId) {
case 1:
$route = 'dtc_devis_modifier';
break;
case 2:
$route = 'dtc_commande_modifier';
break;
case 3:
$route = 'dtc_ordre_reparation_modifier';
break;
case 4:
$route = 'dtc_bon_preparation_modifier';
break;
case 5:
$route = 'dtc_bon_livraison_modifier';
break;
case 6:
$route = 'dtc_facture_afficher';
break;
case 7:
$route = 'dtc_avoir_modifier';
break;
default:
$route = 'dtc_commande_modifier';
break;
}
}
if (count($commande->getAcomptes()) > 0 || count($commande->getReglements()) > 0) {
$hasAcomptes = 'true';
}
$donnees[] = [
'id' => $commande->getId(),
'reference' => $commande->getReference(),
'url' => $this->generateUrl($route, ['id' => $commande->getId()]),
//'acomptes' => $hasAcomptes
];
}
}
}
return new JsonResponse(['commandes' => $donnees, 'hasAcomptes' => $hasAcomptes]);
}
/**
* @Route("/lettrage/facture-et-reglements", name="dtc_lettrage_reglements_et_facture")
*/
public function lettrerAction(Request $request, EntityManagerInterface $em)
{
$allPost = $request->request->all();
$objets = $request->request->get('objets');
$valid = 1;
$repo_commande = $em->getRepository(Commande::class);
$repo_acompte = $em->getRepository(Acompte::class);
$numeroLettrage = 0;
$count = 0;
foreach ($objets as $objet) {
if ($objet['objet'] == 'acompte') {
$objetAmodifier = $repo_acompte->find($objet['id']);
} elseif ($objet['objet'] == 'commande') {
$objetAmodifier = $repo_commande->find($objet['id']);
} else {
$objetAmodifier = '';
}
if ($count == 0 && is_object($objetAmodifier)) {
$client = $objetAmodifier->getClient();
if (is_object($client)) {
$numeroLettrage = $repo_commande->getNumeroLettrage($client);
}
}
$count++;
if (is_object($objetAmodifier)) {
$client = $objetAmodifier->getClient();
$objetAmodifier->setNumeroLettrage($numeroLettrage);
$em->persist($objetAmodifier);
} else {
$valid = 0;
}
}
if ($valid == 1) {
$em->flush();
}
$response = new JsonResponse();
$response->setData([
'post' => $allPost,
'valid' => $valid
//'test' => json_encode(array('essaiT'=>'essaiV'))
]);
return $response;
}
/**
* @Route("/delettrage/facture-et-reglements", name="dtc_delettrage_reglements_et_facture")
*/
public function delettrerAction(Request $request, EntityManagerInterface $em)
{
$allPost = $request->request->all();
$objets = $request->request->get('objets');
$valid = 1;
$repo_commande = $em->getRepository(Commande::class);
$repo_acompte = $em->getRepository(Acompte::class);
$numeroLettrage = null;
foreach ($objets as $objet) {
if ($objet['objet'] == 'acompte') {
$objetAmodifier = $repo_acompte->find($objet['id']);
} elseif ($objet['objet'] == 'commande') {
$objetAmodifier = $repo_commande->find($objet['id']);
} else {
$objetAmodifier = '';
}
if (is_object($objetAmodifier)) {
$numeroLettrage = $objetAmodifier->getNumeroLettrage();
$client = $objetAmodifier->getClient();
if (is_object($client)) {
$acomptesAmodifier = $repo_acompte->findBy([
'numeroLettrage' => $numeroLettrage,
'client' => $client,
]);
if (count($acomptesAmodifier)) {
foreach ($acomptesAmodifier as $acompteAmodifier) {
$acompteAmodifier->setNumeroLettrage(null);
$em->persist($acompteAmodifier);
}
}
$commandesAmodifier = $repo_commande->findBy([
'numeroLettrage' => $numeroLettrage,
'client' => $client,
]);
if (count($commandesAmodifier)) {
foreach ($commandesAmodifier as $commandeAmodifier) {
$commandeAmodifier->setNumeroLettrage(null);
$em->persist($commandeAmodifier);
}
}
}
} else {
$valid = 0;
}
}
if ($valid == 1) {
$em->flush();
}
$response = new JsonResponse();
$response->setData([
'post' => $allPost,
'valid' => $valid
//'test' => json_encode(array('essaiT'=>'essaiV'))
]);
return $response;
}
/*
* @Route("/historique/{entity}/{id}", name="dtc_ajax_historique")
*/
public function historiqueAction(Request $request, $id, $entity, EntityManagerInterface $em)
{
$audits = [];
switch ($entity) {
case 'adresse':
$totalCount = $em->getRepository(Adresse::class)->getHistorique($id, true);
$audits = $em->getRepository(Adresse::class)->getHistorique($id, false);
break;
default:
break;
}
$titreModal = 'Historique des modifications';
$rendu = $this->renderView('FO/Historique/historique.html.twig', [
'audits' => $audits,
]);
return new JsonResponse(['rendu' => $rendu, 'titre' => $titreModal]);
}
/**
* @Route("/fabrication-multiple/load/{id}", name="dtc_ajax_fabrication_multiple_load")
*/
public function fabricationMultipleLoadAction(Request $request, FabricationMultiple $fabricationMultiple, ArticleService $serviceArticle, FabricationService $serviceFabrication
) {
$data = [];
/*
foreach($fabricationMultiple->getFabrications() as $fab){
$dataTmp = array();
$dataTmp['id'] = $fab->getId();
$cump = $serviceArticle->getCumpFabrication3($fab->getArticle(), true, $fab->getQuantite());
$dataTmp['view'] = $this->renderView('GestionComerciale/FabricationMultiple/table-compose-tr.html.twig', array(
'fabrication' => $fab,
'cumpTmp'=> $cump,
));
$data['fabrications'][] = $dataTmp;
}
*/
foreach ($fabricationMultiple->getFabrications() as $fab) {
foreach ($fab->getArticleCommande() as $ac) {
$dataTmp = [];
$dataTmp['id'] = $ac->getId();
$dataTmp['cump'] = $serviceArticle->getCumpOuPrixCondHaAc($ac->getArticle(), '', $ac->getQuantite());
$dataTmp['cumpArrondi'] = round($dataTmp['cump'], 2);
$dataTmp['montantCump'] = round($dataTmp['cump'] * $ac->getQuantite(), 2);
$dataTmp['raf'] = $serviceFabrication->raf($ac->getArticle(), $fab->getId());
$data['articlecommandes'][] = $dataTmp;
}
$dataTmp = [];
$dataTmp['id'] = $fab->getId();
$cump = $serviceArticle->getCumpFabrication3($fab->getArticle(), true, $fab->getQuantite());
$dataTmp['view'] = $this->renderView('GestionComerciale/FabricationMultiple/table-compose-tr.html.twig', [
'fabrication' => $fab,
'cumpTmp' => $cump,
]);
$data['fabrications'][] = $dataTmp;
}
$response = new JsonResponse;
$response->setData($data);
return $response;
}
/**
* @Route("/fabrication/article/load/{article}/{quantite}", name="dtc_ajax_fabrication_article_load")
*/
public function fabricationArticleLoadAction(Request $request, $article, $quantite, ArticleService $serviceArticle)
{
$data = [];
$dataTmp = [];
$dataTmp['id'] = $article;
$dataTmp['cump'] = $serviceArticle->getCumpOuPrixCondHaAc($article, '', $quantite);
$dataTmp['cumpArrondi'] = round($dataTmp['cump'], 2);
$dataTmp['montantCump'] = round($dataTmp['cump'] * $quantite, 2);
$data['articles'][] = $dataTmp;
$response = new JsonResponse;
$response->setData($data);
return $response;
}
/**
* @Route("/commande-article/achat/nouveaux", name="dtc_construire_lignes_article_commande_fournisseur")
*/
public function construireLignesArticleCommandeFournisseurAction(Request $request, EntityManagerInterface $em, ColonneTableauService $serviceColonne,
ArticleService $articleService, FournisseurService $fournisseurService
) {
$repoFournisseur = $em->getRepository(Fournisseur::class);
$repo_taxe = $em->getRepository(Taxe::class);
$fournisseur = $request->query->get('fournisseur');
$commandeId = $request->query->get('commandeId');
//$quantite = $request->query->get('quantite');
$repo_article = $em->getRepository(Article::class);
$data = $request->get('dataTables');
if (empty($data['actions'])) {
$ids = [];
} else {
$ids = $data['actions'];
}
$qtes = $request->get('qte');
$rendu = '';
$commentairePonctuel = '';
//return new JsonResponse(array('rendu'=>$rendu,), 200, array('Content-Type'=>'application/json'));
$colspan = 13;
$tabColonneUser = [];
$tabColonneUser["id"] = 1;
$tabColonneUser["reference"] = 1;
$tabColonneUser["referenceF"] = 1;
$tabColonneUser["libelle"] = 1;
$tabColonneUser["libelleF"] = 1;
$tabColonneUser["qteMini"] = 1;
$tabColonneUser["qteMaxi"] = 1;
$tabColonneUser["ralC"] = 1;
$tabColonneUser["ralF"] = 1;
$tabColonneUser["qteStockCommande"] = 1;
$tabColonneUser["uniteVente"] = 1;
$tabColonneUser["qte"] = 1;
$tabColonneUser["uniteAchat"] = 1;
$tabColonneUser["prixAchatUnitaire"] = 1;
$tabColonneUser["prixHT"] = 1;
$tabColonneUser["CC"] = 1;
$tabColonneUser["qteMiniAchat"] = 1;
$tabColonneUser["conditionnement"] = 1;
$tabColonneUser["txRem"] = 1;
$tabColonneUser["txRemSuppl"] = 1;
$tabColonneUser["fraisAnnexes"] = 1;
$tabColonneUser["ecocontribution"] = 1;
$tabColonneUser["montantHt"] = 1;
$tabColonneUser["totalHT"] = 1;
$tabColonneUser["pump"] = 1;
$tabColonneUser["stock"] = 1;
// TODO CHANGE THIS
$colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormCommandeFournisseur";
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'id') == false) {
$colspan--;
$tabColonneUser["id"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'reference') == false) {
$colspan--;
$tabColonneUser["reference"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'referenceF') == false) {
$colspan--;
$tabColonneUser["referenceF"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'libelle') == false) {
$colspan--;
$tabColonneUser["libelle"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'libelleF') == false) {
$colspan--;
$tabColonneUser["libelleF"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'qteMini') == false) {
$colspan--;
$tabColonneUser["qteMini"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'qteMaxi') == false) {
$colspan--;
$tabColonneUser["qteMaxi"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'ralC') == false) {
$colspan--;
$tabColonneUser["ralC"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'ralF') == false) {
$colspan--;
$tabColonneUser["ralF"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'qteStockCommande') == false) {
$colspan--;
$tabColonneUser["qteStockCommande"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'uniteVente') == false) {
$colspan--;
$tabColonneUser["uniteVente"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'qte') == false) {
$colspan--;
$tabColonneUser["qte"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'uniteAchat') == false) {
$colspan--;
$tabColonneUser["uniteAchat"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'prixAchatUnitaire') == false) {
$colspan--;
$tabColonneUser["prixAchatUnitaire"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'prixHT') == false) {
$colspan--;
$tabColonneUser["prixHT"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'CC') == false) {
$colspan--;
$tabColonneUser["CC"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'qteMiniAchat') == false) {
$colspan--;
$tabColonneUser["qteMiniAchat"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'conditionnement') == false) {
$colspan--;
$tabColonneUser["conditionnement"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'txRem') == false) {
$colspan--;
$tabColonneUser["txRem"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'txRemSuppl') == false) {
$colspan--;
$tabColonneUser["txRemSuppl"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'fraisAnnexes') == false) {
$colspan--;
$tabColonneUser["fraisAnnexes"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'ecocontribution') == false) {
$colspan--;
$tabColonneUser["ecocontribution"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'montantHt') == false) {
$colspan--;
$tabColonneUser["montantHt"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'totalHT') == false) {
$colspan--;
$tabColonneUser["totalHT"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'pump') == false) {
$colspan--;
$tabColonneUser["pump"] = 0;
}
if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur, 'stock') == false) {
$colspan--;
$tabColonneUser["stock"] = 0;
}
foreach ($ids as $id) {
if ( ! empty($qtes[$id])) {
$quantite = floatval($qtes[$id]);
$article = $repo_article->find($id);
if (is_object($article)) {
if ($article->getDivers() == 1) {
/*
$articleTmp = clone $article;
$newRef = $articleTmp->getReference().'-'.time();
$articleTmp->setReference($newRef);
$articleTmp->setParent($article);
$articleTmp->setIdImport($article->getIdImport().'-duplique');
$em->persist($articleTmp);
$em->flush();
$article = $articleTmp;
*/
$conn = $em->getConnection();
$conn->getConfiguration()->setSQLLogger(null);
$tableau_donnee = [];
$tableau_donnee["reference"] = $article->getReference()."-".time();
$tableau_donnee["ral_fournisseur"] = "0";
$tableau_donnee["parent_id"] = $article->getId();
$tableau_donnee["libelle"] = $article->getLibelle();
$tableau_donnee["reference_client"] = $article->getReferenceClient();
$tableau_donnee["reference_fournisseur"] = $article->getReferenceFournisseur();
$tableau_donnee["prix_base"] = $article->getPrixBase();
$dateTmp = new \Datetime;
$tableau_donnee["date"] = $dateTmp->format("Y-m-d H:i:s");
if ($article->getDateMaj() != "") {
$tableau_donnee["date_maj"] = $article->getDateMaj()->format("Y-m-d H:i:s");
}
if ($article->getDateMajPrix() != "") {
$tableau_donnee["date_maj_prix"] = $article->getDateMajPrix()->format("Y-m-d H:i:s");
}
if ($article->getDateSuppression() != "") {
$tableau_donnee["date_supression"] = $article->getDateSuppression()->format("Y-m-d H:i:s");
}
if (is_object($article->getMarque())) {
$tableau_donnee["marque_id"] = $article->getMarque()->getId();
}
$tableau_donnee["description"] = $article->getDescription();
$tableau_donnee["description_courte"] = $article->getDescriptionCourte();
$tableau_donnee["stock"] = "0";
if ($article->getStatut() === true) {
$tableau_donnee["statut"] = 1;
} else {
$tableau_donnee["statut"] = 0;
}
$tableau_donnee["largeur"] = $article->getLargeur();
$tableau_donnee["profondeur"] = $article->getProfondeur();
$tableau_donnee["hauteur"] = $article->getHauteur();
$tableau_donnee["poids"] = $article->getPoids();
if ($article->getAConsigner()) {
$tableau_donnee["a_consigner"] = 1;
} else {
$tableau_donnee["a_consigner"] = 0;
}
if ($article->getStockAuto()) {
$tableau_donnee["stock_auto"] = 1;
} else {
$tableau_donnee["stock_auto"] = 0;
}
if ($article->getArretGamme() === true) {
$tableau_donnee["arret_gamme"] = 1;
} else {
$tableau_donnee["arret_gamme"] = 0;
}
if (is_object($article->getUtilisateur())) {
$tableau_donnee["utilisateur_id"] = $article->getUtilisateur()->getId();
}
if (is_object($article->getRegleTaxe())) {
$tableau_donnee["regle_taxe_id"] = $article->getRegleTaxe()->getId();
}
$tableau_donnee["remise_max"] = $article->getRemiseMax();
$tableau_donnee["type_remise_max"] = $article->getTypeRemiseMax();
$tableau_donnee["seuil_commande_f_mini"] = $article->getSeuilMiniCommandeFournisseur();
$tableau_donnee["seuil_commande_f_maxi"] = $article->getSeuilMaxiCommandeFournisseur();
if (is_object($article->getNiveauUn())) {
$tableau_donnee["niveau_un_id"] = $article->getNiveauUn()->getId();
}
if (is_object($article->getNiveauDeux())) {
$tableau_donnee["niveau_deux_id"] = $article->getNiveauDeux()->getId();
}
if (is_object($article->getNiveauTrois())) {
$tableau_donnee["niveau_trois_id"] = $article->getNiveauTrois()->getId();
}
if (is_object($article->getNiveauQuatre())) {
$tableau_donnee["niveau_quatre_id"] = $article->getNiveauQuatre()->getId();
}
$tableau_donnee["pump"] = $article->getCpump();
$tableau_donnee["commentaire"] = $article->getCommentairePonctuel();
if ($article->getVirtuel()) {
$tableau_donnee["virtuel"] = 1;
} else {
$tableau_donnee["virtuel"] = 0;
}
//$tableau_donnee["prix_vente"]=$article->getLibelle();
$tableau_donnee["prix_vente"] = 0;
$tableau_donnee["taux_marge"] = $article->getTauxMarge();
$tableau_donnee["marge"] = $article->getMarge();
$tableau_donnee["marge_reelle"] = $article->getMargeReelle();
$tableau_donnee["ecotaxe"] = $article->getEcotaxe();
$tableau_donnee["conditionnement"] = $article->getConditionnement();
$tableau_donnee["stock_reserve"] = $article->getStockReserve();
if (is_object($article->getFournisseurDefaut())) {
$tableau_donnee["fournisseur_defaut_id"] = $article->getFournisseurDefaut()->getId();
}
$tableau_donnee["ral_fournisseur"] = "0";
$tableau_donnee["id_import"] = "";
$tableau_donnee["donnees_import"] = "";
if ($article->getMajPrix()) {
$tableau_donnee["maj_prix"] = 1;
} else {
$tableau_donnee["maj_prix"] = 0;
}
if (is_object($article->getUniteMesure())) {
$tableau_donnee["unite_mesure_id"] = $article->getUniteMesure()->getId();
}
if ($article->getAfficherComposantPdfInterne()) {
$tableau_donnee["afficher_composant_pdf_interne"] = 1;
} else {
$tableau_donnee["afficher_composant_pdf_interne"] = 0;
}
if ($article->getAfficherComposantPdfExterne()) {
$tableau_donnee["afficher_composant_pdf_externe"] = 1;
} else {
$tableau_donnee["afficher_composant_pdf_externe"] = 0;
}
if (is_object($article->getCategorieRemiseArticle())) {
$tableau_donnee["categorie_remise_article_id"] = $article->getCategorieRemiseArticle()->getId();
}
$tableau_donnee["temporaire"] = $article->getTemporaire();
$tableau_donnee["libelle_secondaire"] = $article->getLibelleSecondaire();
$tableau_donnee["a_commander"] = "1";
$tableau_donnee["a_fabriquer"] = "0";
$tableau_donnee["quantite_conseillee_mini"] = $article->getQuantiteConseilleeMini();
$tableau_donnee["quantite_conseillee"] = $article->getQuantiteConseillee();
$tableau_donnee["quantite_conseillee_maxi"] = $article->getQuantiteConseilleeMaxi();
if ($article->getArchive() === true) {
$tableau_donnee["archive"] = 1;
} else {
$tableau_donnee["archive"] = 0;
}
$tableau_donnee["coefficient_px_base_px_vente"] = $article->getCoefficientPrixBaseVente();
$tableau_donnee["nom_web"] = $article->getNomWeb();
$tableau_donnee["reference_web"] = $article->getReferenceWeb();
$tableau_donnee["reference_fournisseur_web"] = $article->getReferenceFournisseurWeb();
$tableau_donnee["description_web"] = $article->getDescriptionWeb();
$tableau_donnee["resume_web"] = $article->getResumeWeb();
$tableau_donnee["frais_ports_texte_web"] = $article->getFraisPortsTexteWeb();
$tableau_donnee["message_qd_en_stock"] = $article->getMessageQdEnStockWeb();
if (is_object($article->getArticleEnconsigne())) {
$tableau_donnee["article_enconsigne_id"] = $article->getArticleEnconsigne()->getId();
}
$tableau_donnee["reference_appel_1"] = $article->getReferenceAppel1();
$tableau_donnee["reference_appel_2"] = $article->getReferenceAppel2();
$tableau_donnee["reference_appel_3"] = $article->getReferenceAppel3();
$tableau_donnee["reference_appel_4"] = $article->getReferenceAppel4();
$tableau_donnee["reference_appel_5"] = $article->getReferenceAppel5();
$tableau_donnee["reference_appel_6"] = $article->getReferenceAppel6();
$tableau_donnee["reference_appel_7"] = $article->getReferenceAppel7();
$tableau_donnee["reference_appel_8"] = $article->getReferenceAppel8();
$tableau_donnee["reference_appel_9"] = $article->getReferenceAppel9();
$tableau_donnee["reference_appel_10"] = $article->getReferenceAppel10();
$tableau_donnee["reference_appel_11"] = $article->getReferenceAppel11();
if ($article->getMainOeuvre() === true) {
$tableau_donnee["main_oeuvre"] = 1;
} else {
$tableau_donnee["main_oeuvre"] = 0;
}
$tableau_donnee["stock_reserve_fabrication"] = $article->getStockReserveFabrication();
if (is_object($article->getType())) {
$tableau_donnee["type_id"] = $article->getType()->getId();
}
if (is_object($article->getFamilleCompta())) {
$tableau_donnee["famille_compta_id"] = $article->getFamilleCompta()->getId();
}
if ($article->getPrestation()) {
$tableau_donnee["prestation"] = 1;
} else {
$tableau_donnee["prestation"] = 0;
}
if ($article->getNonStocke() === true) {
$tableau_donnee["non_stocke"] = 1;
} else {
$tableau_donnee["non_stocke"] = 0;
}
if ($article->getNonCommandable()) {
$tableau_donnee["non_commandable"] = 1;
} else {
$tableau_donnee["non_commandable"] = 0;
}
if (is_object($article->getParent())) {
$tableau_donnee["parent_id"] = $article->getParent()->getId();
}
$tableau_donnee["divers"] = $article->getDivers();
if ($article->getMouvemente() === true) {
$tableau_donnee["mouvemente"] = 1;
} else {
$tableau_donnee["mouvemente"] = 0;
}
if ($article->getNumSerieObligatoire()) {
$tableau_donnee["num_serie_obligatoire"] = 1;
} else {
$tableau_donnee["num_serie_obligatoire"] = 0;
}
if (is_object($article->getArticleRemplacement())) {
$tableau_donnee["article_remplacement_id"] = $article->getArticleRemplacement()->getId();
}
if ($article->getMajPoids()) {
$tableau_donnee["maj_poids"] = 1;
} else {
$tableau_donnee["maj_poids"] = 0;
}
if ($article->getMajPrixBase()) {
$tableau_donnee["maj_prix_base"] = 1;
} else {
$tableau_donnee["maj_prix_base"] = 0;
}
if ($article->getEstCommentaire()) {
$tableau_donnee["est_commentaire"] = 1;
} else {
$tableau_donnee["est_commentaire"] = 0;
}
$tableau_donnee["cond_achat"] = $article->getConditionnementAchat();
$tableau_donnee["seuil_critique"] = $article->getSeuilCritique();
if (is_object($article->getRegleTaxeAchat())) {
$tableau_donnee["regle_taxe_achat_id"] = $article->getRegleTaxeAchat()->getId();
}
$conn->insert('article__article', $tableau_donnee);
$idNouveauArticle = $conn->lastInsertId();
$article = $repo_article->find($idNouveauArticle);
}
$a = [];
$a['position'] = "";
$a['article'] = $article;
$a['ecocontribution'] = floatval($article->getEcocontribution());
$a['libelle'] = $article->getLibelle();
if ($quantite != '' && is_numeric($quantite)) {
$a['quantite'] = $quantite;
$a['ral'] = $quantite;
} else {
$a['quantite'] = "1";
$a['ral'] = "1";
}
//$a['estCommentaire']=$article->getEstCommentaire();
if ($article->getEstCommentaire()) {
$a['estCommentaire'] = 1;
} else {
$a['estCommentaire'] = 0;
}
$a['commentaire'] = "";
$a['commentaireSuppl'] = "";
$a['commentairePrive'] = "";
$a['remise'] = "0";
$a['remiseSupplementaire'] = "0";
$a['totalHt'] = $article->getPrixBase();
$a['prixBase'] = $article->getPrixBase();
//recuperer la condition d'achat par défaut
$repoConditionsAchat = $em->getRepository(ConditionAchat::class);
//$condition = $repoConditionsAchat->findBy(array('article' => $article->getId(), 'defaut' => 1), array('id'=>'ASC'),1,0);
if ($fournisseur != '') {
$condition = $repoConditionsAchat->findOneBy([
'article' => $article->getId(),
'fournisseur' => $fournisseur,
'defaut' => 1,
]);
}
if ( ! isset($condition) || ! is_object($condition)) {
$condition = $repoConditionsAchat->findOneBy([
'article' => $article->getId(),
'fournisseur' => $fournisseur,
]);
}
/*
if(count($condition) > 0)
$condition = $condition[0];
else
$condition = $repoConditionsAchat->findOneBy(array('article' => $article->getId()));
*
*/
$a['coefficientConditionnement'] = 1;
$a['fraisAnnexes'] = 0;
if (is_object($condition)) {
$a['coefficientConditionnement'] = $condition->getCoefficientConditionnement();
if ($condition->getTauxRemise() != '') {
$a['remise'] = $condition->getTauxRemise();
}
if ($condition->getTauxRemiseSupplementaire() != '') {
$a['remiseSupplementaire'] = $condition->getTauxRemiseSupplementaire();
}
if ($condition->getPrixAchatBrut() != '') {
//$a['prixBase']= $condition->getPrixAchatBrut() * $condition->getConditionnement() / $condition->getCoefficientConditionnement() ;
$a['prixBase'] = $condition->getPrixAchatBrut();
}
if ($condition->getLibelle() != '') {
$a['libelle'] = $condition->getLibelle();
}
if ($quantite != '' && is_numeric($quantite)) {
$a['quantite'] = $quantite;
} elseif ($condition->getQuantite() != '') {
$a['quantite'] = $condition->getQuantite();
}
$a['conditionAchat'] = $condition;
$a['fraisAnnexes'] = $condition->getFraisAnnexes();
}
$a['couleur'] = $articleService->getCouleurEtatStock($article, $a['quantite']);
$fournisseur = $repoFournisseur->find($fournisseur);
$taxe = $repo_taxe->find(5);
if (is_object($fournisseur)) {
$taxe = $fournisseurService->getTaxe($fournisseur, $article);
}
$a['tva'] = $taxe->getTaux();
$a['taxe'] = $taxe;
$rendu .= $this->renderView('GestionComerciale/ArticleCommande/template_tr_fournisseur.html.twig', [
'a' => $a,
'boucle' => "0",
'numeroLigne' => "0",
'fournisseur' => $fournisseur,
'commandeId' => $commandeId,
'tabColonneUser' => $tabColonneUser,
]);
$commentairePonctuel .= $article->getCommentairePonctuel();
}
}
}
return new JsonResponse(['rendu' => $rendu, 'commentairePonctuel' => $commentairePonctuel]);
}
/**
* @Route("/article/conditionnement-achat/recherche", name="dtc_ajax_conditionnement_achat_recherche")
*/
public function articleConditionnementAchatRechercheAction(Request $request, EntityManagerInterface $em)
{
$conditionnementsAchat = [];
$q = $request->request->get('q');
if ($q != '') {
$conditionnements = $em->getRepository(ConditionnementAchat::class)->findByIdentifiant($q);
if (count($conditionnements) > 0) {
foreach ($conditionnements as $conditionnement) {
$conditionnementsAchat[] = [
'article' => $conditionnement->getArticle()->getId(),
'quantite' => $conditionnement->getQuantite(),
];
}
}
}
$response = new JsonResponse();
$response->setData([
'conditionnements' => $conditionnementsAchat,
]);
return $response;
}
/**
* @Route("/article/ajax/recherche", name="dtc_ajax_article_recherche")
*/
public function articleAjaxRechercheAction(Request $request, EntityManagerInterface $em)
{
$articles = [];
$q = $request->request->get('q');
if ($q != '') {
//$article = $em->getRepository('DTCArticlesBundle:Article')->findOneBy(array('reference'=>$q));
$article = $em->getRepository(Article::class)->getArticleParReference($q, ["mouvemente" => "1"]);
if ( ! is_object($article)) {
$article = $em->getRepository(Article::class)->getArticleParReference($q, ["mouvemente" => "0"]);
}
if (is_object($article)) {
$quantite = 1;
if (count($article->getConditionnementAchatEan()) > 0) {
foreach ($article->getConditionnementAchatEan() as $condAchatEan) {
if ($condAchatEan->getIdentifiant() == $q) {
$quantite = $condAchatEan->getQuantite();
break;
}
}
}
$articles[] = [
'article' => $article->getId(),
'quantite' => $quantite,
];
}
}
$response = new JsonResponse();
$response->setData([
'articles' => $articles,
]);
return $response;
}
/**
* @Route("", name="")
*/
public function __articleAjaxRechercheAction(Request $request, EntityManagerInterface $em, TranslatorInterface $translator, ValidatorInterface $validator)
{
$articles = [];
$q = $request->request->get('q');
if ($q != '') {
$article = $em->getRepository(Article::class)->findOneBy(['reference' => $q]);
if (is_object($article)) {
$articles[] = [
'article' => $article->getId(),
'quantite' => 1,
];
}
}
$response = new JsonResponse();
$response->setData([
'articles' => $articles,
]);
return $response;
}
/**
* @Route("/commande/{commande}/recharger-numeros-serie", name="dtc_ajax_recharger_numeros_serie")
*/
public function rechargerNumerosSerieAction(Request $request, Commande $commande)
{
$rendu = $this->renderView('GestionComerciale/Commande/numeros-series.html.twig', [
'commande' => $commande,
]);
$response = new JsonResponse;
$response->setData(["rendu" => $rendu]);
return $response;
}
/**
* @Route("/vente/commande/ajax/verifier-action/{id}", name="dtc_commande_verifier_action")
*/
public function verifierActionAction(Request $request, Commande $commande, EntityManagerInterface $em, TranslatorInterface $translator)
{
$action = $request->request->get('action');
$statutCommande = $commande->getStatutCommande();
$valide = 0;
$rendu = '';
//$erreur = '';
if (is_object($statutCommande)) {
switch ($action) {
case 'preparer':
if (in_array($statutCommande->getOrdre(), [1, 12])) {
//à préparer, mise en attente préparation
$valide = 1;
} else {
$this->addFlash('warning', $translator->trans('Le statut de commande actuel ne permet pas cette action!'));
}
break;
case 'emballer':
if (in_array($statutCommande->getOrdre(), [3, 13])) {
//préparé, mise en attente emballage
$valide = 1;
} else {
$this->addFlash('warning', $translator->trans('Le statut de commande actuel ne permet pas cette action!'));
}
break;
}
}
if ( ! $valide) {
$rendu = $this->renderView('layout-errors.html.twig', [//'erreur' => array('test'),
]);
}
$response = new JsonResponse;
$response->setData(["valide" => $valide, 'rendu' => $rendu]);
return $response;
}
/**
* @Route("/commande-article/recharger/tva", name="dtc_recharger_tva_article_commande")
*/
public function rechargerTvaLigneArticleCommandeAction(Request $request, EntityManagerInterface $em, ArticleService $serviceArticle)
{
$articlesIds = $request->query->get('articlesIds');
$id_client = $request->query->get('id_client');
$id_adresse = $request->query->get('id_adresse');
$code_iso = $request->query->get('code_iso');
$client = '';
$adresse = '';
if ( ! empty($id_adresse)) {
$adresse = $em->getRepository(Adresse::class)->find($id_adresse);
}
if ( ! empty($id_client)) {
$client = $em->getRepository(Client::class)->find($id_client);
}
$repo_article = $em->getRepository(Article::class);
$taxes = [];
if (is_array($articlesIds) && count($articlesIds)) {
foreach ($articlesIds as $articleId) {
if (empty($taxes[$articleId])) {
$article = $repo_article->find($articleId);
if (is_object($article)) {
$taxe = $serviceArticle->getTaxe($article, $client, $adresse);
if (is_object($taxe)) {
$taxes[$articleId] = ['id' => $taxe->getId(), 'taux' => $taxe->getTaux()];
}
}
}
}
}
$taxeCommandeRetour = ['id' => '', 'taux' => ''];
$taxeCommande = $serviceArticle->getTaxe('', $client, $adresse, $code_iso);
if (is_object($taxeCommande)) {
$taxeCommandeRetour = ['id' => $taxeCommande->getId(), 'taux' => $taxeCommande->getTaux()];
}
return new JsonResponse([
'taxes' => $taxes,
'taxeCommande' => $taxeCommandeRetour,
]
);
}
/**
* @Route("/commande/copies-lignes/{id}", name="dtc_commande_copies_lignes")
*/
public function copiesLignesAction(Request $request, Commande $commande, EntityManagerInterface $em, TranslatorInterface $translator, ValidatorInterface $validator,
ArticleService $articleService, CommandeService $commandeService
) {
$titre_modal = "Copies lignes";
$get = $request->query->all();
//$ids=$get['ids'];
$copieLigne = new Commande();
//print_r($ids);
$form = $this->createForm(CopiesLignesType::class, $copieLigne);
$errors = "";
$form->handleRequest($request);
$tab_lignes = [];
$repo_article_commande = $em->getRepository(ArticleCommande::class);
$tab_lignes = $repo_article_commande->findBy(["commande" => $commande]);
if ($form->isSubmitted()) {
$form_valide = false;
$post = $request->request->all();
$url = "";
//print_r($post);
//exit;
if ( ! empty($post["choixCopie"]) && ! empty($post["articleCopies"])) {
$form_valide = true;
}
if ( ! $form_valide) {
$error = new FormError("Vous devez sélectionnez au moins une ligne à copier !");
$form->get('reference')->addError($error);
} else {
}
if ($form->isValid()) {
if ( ! empty($post["choixCopie"])) {
$tabCopies = [];
if (count($post["articleCopies"])) {
foreach ($post["articleCopies"] as $copie) {
$tabCopies["articles"]["idArticleCommande"][] = $copie;
}
}
//http://lbdp.local.tl/app_dev.php/vente/comptoir/nouveau?forceEnregistrement=devis&copies[articles][idArticleCommande][0]=802433&copies[articles][idArticleCommande][1]=802434
if ($post["choixCopie"] == "devis") {
$url = $this->generateUrl('dtc_comptoir_ajouter', ["forceEnregistrement" => "devis", "copies" => $tabCopies]);
} elseif ($post["choixCopie"] == "commande") {
$url = $this->generateUrl('dtc_comptoir_ajouter', ["forceEnregistrement" => "commande", "copies" => $tabCopies]);
} elseif ($post["choixCopie"] == "existant") {
$repo_commande = $em->getRepository(Commande::class);
$commande_obj = $repo_commande->find($post["doc_existant_id"]);
if (is_object($commande_obj) && is_object($commande_obj->getTypeDocumentCommercial())) {
$copies = $tabCopies;
$lancerSauvegarde = false;
/*
COPIES DE LIGNE DEPUIS UN AUTRE DEVIS / COMMANDE
*/
//echo "YYYYYYY";
$tab_article_commande_copies = [];
if ($copies != '') {
$repo_article_commande = $em->getRepository(ArticleCommande::class);
$positionDepart = count($commande_obj->getArticleCommande());
if ( ! empty($this->getParameter('article_frais_facturation'))) {
$position_ff = $positionDepart + count($copies['articles']['idArticleCommande']);
$ac_ff_obj = $repo_article_commande->findOneBy(["article" => $this->getParameter('article_frais_facturation'), "commande" => $commande_obj]);
if (is_object($ac_ff_obj)) {
$positionDepart--;
$conn = $em->getConnection();
$tableau_donnee_article_ff = ["position" => $position_ff];
$conn->update('commerciale__article_commande', $tableau_donnee_article_ff, ['id' => $ac_ff_obj->getId()]);
}
}
for ($i = 0; $i < count($copies['articles']['idArticleCommande']); $i++) {
$articleCommandeClone = $repo_article_commande->find($copies['articles']['idArticleCommande'][$i]);
//echo "lll===>".$articleCommandeClone->getLibelle();
//exit;
if (is_object($articleCommandeClone)) {
//$forceEnregistrement = true;
$lancerSauvegarde = true;
$articleCommande = new ArticleCommande();
$articleCommande->setArticle($articleCommandeClone->getArticle());
$articleCommande->setLibelle($articleCommandeClone->getLibelle());
$articleCommande->setLibelleSecondaire($articleCommandeClone->getLibelleSecondaire());
$articleCommande->setPrixBase($articleCommandeClone->getPrixBase());
$articleCommande->setQuantite($articleCommandeClone->getQuantite());
//$articleCommande->setRal($articleCommandeClone->getQuantite());
$articleCommande->setRalClient($articleCommandeClone->getQuantite());
$articleCommande->setRemise($articleCommandeClone->getRemise());
$articleCommande->setCommentaire($articleCommandeClone->getCommentaire());
$articleCommande->setCommentaireSuppl($articleCommandeClone->getCommentaireSuppl());
$articleCommande->setCommentairePrive($articleCommandeClone->getCommentairePrive());
$articleCommande->setEcocontribution($articleCommandeClone->getEcocontribution());
$articleCommande->setRemiseSupplementaire($articleCommandeClone->getRemiseSupplementaire());
$articleCommande->setDate(new \DateTime());
$articleCommande->setDateMaj(new \DateTime());
$articleCommande->setDateLivraisonTheorique(null);
$articleCommande->setTransporteur(null);
$articleCommande->setFraisPort(0);
$articleCommande->setLitige(null);
$articleCommande->setPosition($i + $positionDepart);
$articleCommande->setDevis(null);
$articleCommande->setFabrication(null);
$articleCommande->setArticleCommande(null);
$articleCommande->setArticleCommandeParent(null);
$articleCommande->setConditionAchat(null);
//$articleCommande->setidFusion(NULL);
$articleCommande->setRemiseInitial(null);
$articleCommande->setArticleAssocie(null);
$articleCommande->setQuantiteReprise(0);
$articleCommande->setQuantiteDejaPreparee(0);
$articleCommande->setQuantiteDejaPrepareeSimplifie(0);
$articleCommande->setForce(0);
$articleCommande->setCommande(null);
$articleCommande->setPoids($articleCommandeClone->getPoids());
$articleCommande->setTotalHt($articleCommandeClone->getTotalHt());
$articleCommande->setTva($articleCommandeClone->getTva());
$articleCommande->setResteAreprendre($articleCommandeClone->getquantite());
$articleCommande->setTaxe($articleCommandeClone->getTaxe());
$articleCommande->setQuantiteDispo($articleCommandeClone->getQuantiteDispo());
$articleCommande->setCoefficientConditionnement($articleCommandeClone->getCoefficientConditionnement());
$articleCommande->setArticleCommandeAssocie(null);
$tab_article_commande_copies[] = $articleCommandeClone;
$commande_obj->addArticleCommande($articleCommande);
$articleCommande->setCommande($commande_obj);
$em->persist($articleCommande);
if ($commande_obj->getTypeDocumentCommercial() == TypeDocumentCommercial::COMMANDE) {
$article = $articleCommande->getArticle();
$reserveDiversComposes = ! $article->getDiversComposes() || ($article->getDiversComposes() && $article->getNomenclatureValidee());
//if($reservationPrestashop && $premiereReservationPrestashop && ($operation == "commande" || $operation == "bp") && $reserveDiversComposes) {
if ($reserveDiversComposes) {
if ($article->getVirtuel() == true or $article->getNonStocke() == true or $article->getNonCommandable() == true or $article->getMainOeuvre(
) == true) {
$article->setStockReserve(0);
if ($article->getProduitInterne() == true) {
$variation = floatval($articleCommande->getQuantite());
$articleService->modifierStockReserveComposants($article, $variation);
}
} elseif (floatval($articleCommande->getQuantite()) != 0) {
//$commande->setCommentaire('tt '.$article->getStockReserve().' / '.$a->getQuantite());
$article->setStockReserve(floatval($article->getStockReserve()) + floatval($articleCommande->getQuantite()));
}
$em->persist($article);
}
$commande_obj->setStatutAmodifier(1);
}
}
}
}
if (count($tab_article_commande_copies) > 0) {
foreach ($tab_article_commande_copies as $copie) {
$commandeService->creerHistorique(
$commande_obj,
'copie-ligne',
[
"message" => " - Ajout de l'article ".$copie->getArticle()->getReference()." depuis ".$copie->getCommande()->getReference(),
]
);
}
}
$em->flush();
if ($commande_obj->getTypeDocumentCommercial() == TypeDocumentCommercial::DEVIS) {
$url = $this->generateUrl('dtc_devis_modifier', ["id" => $commande_obj->getId(), 'sauvegarde' => 1]);
} elseif ($commande_obj->getTypeDocumentCommercial() == TypeDocumentCommercial::COMMANDE) {
$url = $this->generateUrl('dtc_commande_modifier', ["id" => $commande_obj->getId(), 'sauvegarde' => 1]);
}
}
}
}
$this->addFlash('notice', $translator->trans('Lignes copiées avec succès !'));
return new JsonResponse(['rendu' => '', 'valide' => '1', 'url' => $url]);
} else {
$errors = $validator->validate($copieLigne);
$rendu = $this->renderView(
'GestionComerciale/ArticleCommande/copies_lignes.html.twig',
['tabLignes' => $tab_lignes, 'form' => $form->createView(), 'errors' => $errors]
);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
}
$rendu = $this->renderView('GestionComerciale/ArticleCommande/copies_lignes.html.twig', [
'tabLignes' => $tab_lignes,
'form' => $form->createView(),
'errors' => $errors,
]);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal, 'width' => 900]);
}
}