| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use Illuminate\Support\Carbon;
- use Illuminate\Support\Facades\DB;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Validator;
- use App\Http\Controllers\ResponseController;
- use App\Http\Controllers\ResourcesController;
- use App\Http\Controllers\EncryptionController;
- class InvoiceControlController extends Controller {
- private $responseController;
- private $encController;
- private $resourcesController;
- public function __construct() {
- $this->responseController = new ResponseController();
- $this->encController = new EncryptionController();
- $this->resourcesController = new ResourcesController();
- }
- public function compareInvoice(Request $request) {
- $validator = Validator::make($request->all(), [
- 'IDARCHIVO' => 'required|string',
- 'USER' => 'required|string',
- 'LINE_NUMBER' => 'required|string',
- 'REQUEST_LINE' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- true,
- "ERR_INVOICE_COMPARE000: Se encontraron uno o más errores.",
- $this->responseController->makeErrors($validator->errors()->messages()),
- 401
- );
- }
- $responseData = $request->all();
- $idArchivo = $this->encController->decrypt($responseData['IDARCHIVO']);
- try {
- $arrLineRequestData = DB::table('S002V01TLINE')
- ->where('LINE_NULI', '=', $responseData['LINE_NUMBER'])
- ->where('LINE_IDLI', '=', $responseData['REQUEST_LINE'])
- ->where('LINE_ESTA', '=', 'En espera')
- ->where('ARSE_ESTA', '=', 'Activo')
- ->join('S002V01TARSE', 'LINE_IDLI','=', 'ARSE_IDLI')
- ->get([
- 'LINE_IDLI',
- 'LINE_NUPR',
- 'LINE_NUOR',
- 'LINE_OTPR',
- 'LINE_OTCO',
- 'ARSE_IDAS',
- 'ARSE_IDLI',
- 'ARSE_IDAR',
- 'ARSE_NUPR',
- 'ARSE_IDIN',
- 'ARSE_CANT',
- 'ARSE_PRTO',
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(
- true,
- "ERR_INVOICE_COMPARE001: Ocurrió un error al obtener la información de la base de datos del documento.",
- $th->getMessage(),
- 500
- );
- }
- if (empty($arrLineRequestData)) {
- return $this->responseController->makeResponse(true, "ERR_INVOICE_COMPARE002: No se pudo obtener la información de la línea de solicitud de compra.", [], 401);
- }
- try {
- $fileTempData = (array) DB::table('S002V01TARTE')
- ->where('ARTE_NULI', '=', $responseData['LINE_NUMBER'])
- ->where('ARTE_IDAR', '=', $idArchivo)
- ->where('ARTE_ESTA', '=', 'Activo')
- ->first([
- 'ARTE_IDAR',
- 'ARTE_NULI',
- 'ARTE_NOAR',
- 'ARTE_EXTE',
- 'ARTE_TAMA',
- 'ARTE_UBTE',
- 'ARTE_ESTA',
- 'ARTE_USRE',
- 'ARTE_FERE',
- 'ARTE_USMO',
- 'ARTE_FEMO',
- 'ARTE_FEAR',
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(
- true,
- "ERR_INVOICE_COMPARE003: Ocurrió un error al obtener la información de la base de datos del documento.",
- $th->getMessage(),
- 500
- );
- }
- if (empty($fileTempData)) {
- return $this->responseController->makeResponse(true, "ERR_INVOICE_COMPARE004: No se pudo obtener la información del documento.", [], 401);
- }
- if ( !file_exists($fileTempData['ARTE_UBTE']) ) {
- return $this->responseController->makeResponse(true, "ERR_INVOICE_COMPARE005: No se pudo obtener el documento.", [], 401);
- }
- try {
- $xml = simplexml_load_file($fileTempData['ARTE_UBTE'], 'SimpleXMLElement', LIBXML_NOCDATA);
- $ns = $xml->getNamespaces(true);
- $xml->registerXPathNamespace('c', $ns['cfdi']);
- $xml->registerXPathNamespace('t', $ns['tfd']);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(
- true,
- "ERR_INVOICE_COMPARE006: Ocurrió un error al obtener la información del documento.",
- $th->getMessage(),
- 500
- );
- }
- // echo "<pre>";
- $arrConceptos = $xml->xpath('//cfdi:Comprobante//cfdi:Conceptos//cfdi:Concepto');
- $arrConceptos = json_decode(json_encode($arrConceptos), true);
- foreach ($arrConceptos as $keyConceptos => $conceptos) {
- $conceptos = $conceptos['@attributes'];
- // print_r($conceptos);
- // return $conceptos;
- }
- return $arrLineRequestData;
- }
- }
|