|
|
@@ -25,7 +25,8 @@ class InvoiceControlController extends Controller {
|
|
|
|
|
|
public function compareInvoice(Request $request) {
|
|
|
$validator = Validator::make($request->all(), [
|
|
|
- 'IDARCHIVO' => 'required|string',
|
|
|
+ 'IDARCHIVOPDF' => 'required|string',
|
|
|
+ 'IDARCHIVOXML' => 'required|string',
|
|
|
'USER' => 'required|string',
|
|
|
'LINE_NUMBER' => 'required|string',
|
|
|
'REQUEST_LINE' => 'required|integer',
|
|
|
@@ -41,7 +42,8 @@ class InvoiceControlController extends Controller {
|
|
|
|
|
|
$responseData = $request->all();
|
|
|
|
|
|
- $idArchivo = $this->encController->decrypt($responseData['IDARCHIVO']);
|
|
|
+ $idArchivoXml = $this->encController->decrypt($responseData['IDARCHIVOXML']);
|
|
|
+ $idArchivoPdf = $this->encController->decrypt($responseData['IDARCHIVOPDF']);
|
|
|
|
|
|
try {
|
|
|
$arrLineRequestData = DB::table('S002V01TLINE')
|
|
|
@@ -80,7 +82,7 @@ class InvoiceControlController extends Controller {
|
|
|
try {
|
|
|
$fileTempData = (array) DB::table('S002V01TARTE')
|
|
|
->where('ARTE_NULI', '=', $responseData['LINE_NUMBER'])
|
|
|
- ->where('ARTE_IDAR', '=', $idArchivo)
|
|
|
+ ->where('ARTE_IDAR', '=', $idArchivoXml)
|
|
|
->where('ARTE_ESTA', '=', 'Activo')
|
|
|
->first([
|
|
|
'ARTE_IDAR',
|
|
|
@@ -127,15 +129,62 @@ class InvoiceControlController extends Controller {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- // 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;
|
|
|
+ $responseValidateEmisor = $this->validateEmisorCfdi($xml);
|
|
|
+
|
|
|
+ $responseValidateReceptor = $this->validateReceptorCfdi($xml);
|
|
|
+ return $responseValidateEmisor;
|
|
|
+
|
|
|
+ return $arrEmisor;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function validateEmisorCfdi($xml) {
|
|
|
+ $responseValidate = array('error' => false, 'msg' => '', 'response' => []);
|
|
|
+
|
|
|
+ $arrEmisor = $xml->xpath('//cfdi:Comprobante//cfdi:Emisor');
|
|
|
+ $arrEmisor = json_decode(json_encode($arrEmisor), true);
|
|
|
+ $arrEmisor = $arrEmisor[0]['@attributes'];
|
|
|
+
|
|
|
+ try {
|
|
|
+ $objTaxInformation = (array) DB::table('S002V01TINFI')
|
|
|
+ ->where('INFI_ESTA','=','Activo')
|
|
|
+ ->first([
|
|
|
+ 'INFI_NOFI AS NOMBRE_FISCAL',
|
|
|
+ 'INFI_XRFC AS RFC',
|
|
|
+ 'INFI_CORF AS CODIGO_REGIMEN',
|
|
|
+ ]);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ $responseValidate['error'] = true;
|
|
|
+ $responseValidate['msg'] = "ERR_INVOICE_VALIDATEEMISOR000: Ocurrió un error al obtener la información físcal.";
|
|
|
+ $responseValidate['response'] = $th->getMessage();
|
|
|
}
|
|
|
|
|
|
- return $arrLineRequestData;
|
|
|
+ if (empty($objTaxInformation)) {
|
|
|
+ $responseValidate['error'] = true;
|
|
|
+ $responseValidate['msg'] = "ERR_INVOICE_VALIDATEEMISOR001: No se encontró la información físcal";
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($objTaxInformation['NOMBRE_FISCAL'] != $arrEmisor['Nombre']) {
|
|
|
+ $responseValidate['error'] = true;
|
|
|
+ $responseValidate['response'][] = 'Ocurrió un error al válidar el Nombre Fiscal del emisor de la factura.';
|
|
|
+ }
|
|
|
+ if ($objTaxInformation['RFC'] != $arrEmisor['Rfc']) {
|
|
|
+ $responseValidate['error'] = true;
|
|
|
+ $responseValidate['response'][] = 'Ocurrió un error al válidar el R.F.C del emisor de la factura.';
|
|
|
+ }
|
|
|
+ if ($objTaxInformation['CODIGO_REGIMEN'] != $arrEmisor['RegimenFiscal']) {
|
|
|
+ $responseValidate['error'] = true;
|
|
|
+ $responseValidate['response'][] = 'Ocurrió un error al válidar el Regimen Fiscal del emisor de la factura.';
|
|
|
+ }
|
|
|
+
|
|
|
+ return $responseValidate;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function validateReceptorCfdi($xml) {
|
|
|
+ $responseValidate = array('error' => false, 'msg' => '', 'response' => []);
|
|
|
+
|
|
|
+ $arrReceptor = $xml->xpath('//cfdi:Comprobante//cfdi:Receptor');
|
|
|
+ $arrReceptor = json_decode(json_encode($arrReceptor), true);
|
|
|
+ $arrReceptor = $arrReceptor[0]['@attributes'];
|
|
|
+
|
|
|
}
|
|
|
}
|