Commit b6adb0d9 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Fix : Commande spent:list <PFI>

parent 4d23b456
Loading
Loading
Loading
Loading
Loading
+53 −7
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ use Oscar\Service\PersonService;
use Oscar\Service\SpentService;
use Oscar\Service\TimesheetService;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableCell;
use Symfony\Component\Console\Helper\TableCellStyle;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@@ -61,28 +63,71 @@ class OscarSpentListCommand extends OscarCommandAbstract

        /** @var SpentService $spentService */
        $spentService = $this->getServicemanager()->get(SpentService::class);

// 07 64 41 68 47 - 6k
        try {

            $grouped = $spentService->getGroupedSpentsDatas($pfi);
            $styleNumber = new TableCellStyle(['align' => 'right']);
            $money = function($value) use ($styleNumber){
                $amount = number_format($value, 2, ',', ' ');
                return new TableCell($amount, ['style' => $styleNumber]);
            };

            $grouped = $spentService->getGroupedSpentsDatas($pfi);
            foreach ($grouped as $numPiece=>$infos) {
                if( $numPiece === 'byMasses' ){
                    continue;
                }
                if( !array_key_exists('ids', $infos) || !is_array($infos['ids']) ) {
                    var_dump($infos);
                    die('ici');
                }
                $text = is_array($infos['text']) ? implode(',', $infos['text']) : $infos['text'];
                if( strlen($text) > 40 ){
                    $text = substr($text, 0, 40) . '...';
                }

                $out[] = [
                    $numPiece,
                    //implode(',', $infos['syncIds']),
                    implode(',', $infos['text']),
                    $infos['montant'],
                    implode(',', $infos['compteBudgetaire']),
                    $text,
                    $money($infos['montant']),
                    implode(',',$infos['masse']),
                    is_array($infos['compteBudgetaire']) ? implode(',', $infos['compteBudgetaire']) : $infos['compteBudgetaire'],
                    $infos['datecomptable'],
                    $infos['datepaiement'],
                    $infos['annee'],
                    $infos['refPiece'],
                    $infos['ids'][0].' +'.count($infos['ids']),
                    ( array_key_exists('ids', $infos) && is_array($infos['ids']) ? count($infos['ids']) : $infos['ids']),
                ];
            }
            $headers = ['N°Pièce', /*'SIFACID',*/ 'Description', 'Montant', 'Date Comptable', 'Date Paiement', 'Année', 'N° Réf Pièce', 'IDs'];
            $headers = ['N°Pièce', /*'SIFACID',*/ 'Description', 'Montant','Masse','Compte', 'Date Comptable', 'Date Paiement', 'Année', 'N° Réf Pièce', 'IDs'];

            $io->table($headers, $out);

//            $nb = count($grouped['byMasses']['N.B']['spents']);
//            if( $nb ){
//                $io->warning(sprintf("Il y a %s ligne(s) de dépenses non-attribuée(s) à une masse comptable", $nb));
//
//                $out = [];
//                foreach ($grouped['byMasses']['N.B']['spents'] as $numPiece=>$infos) {
//
//                    $out[] = [
//                        $numPiece,
//                        //implode(',', $infos['syncIds']),
//                        is_array($infos['text']) ? implode(',', $infos['text']) : $infos['text'],
//                        $money($infos['montant']),
//                        implode(',',$infos['masse']),
//                        is_array($infos['compteBudgetaire']) ? implode(',', $infos['compteBudgetaire']) : $infos['compteBudgetaire'],
//                        $infos['datecomptable'],
//                        $infos['datepaiement'],
//                        $infos['annee'],
//                        $infos['refPiece'],
//                        ( array_key_exists('ids', $infos) && is_array($infos['ids']) ? count($infos['ids']) : $infos['ids']),
//                    ];
//                }
//                $io->table($headers, $out);
//            }
            return self::SUCCESS;
//            $repport = $connector->execute();
//            foreach ($repport->getRepportStates() as $type => $out) {
//                $short = substr($type, 0, 3);
@@ -93,6 +138,7 @@ class OscarSpentListCommand extends OscarCommandAbstract
//            }
        } catch (\Exception $e) {
            $io->error($e->getMessage());
            return self::FAILURE;
        }
    }
}
 No newline at end of file