Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.70 KB | None | 0 0
  1. Too few arguments to function AppJobsImportDocumentJob::__construct
  2. (), 0 passed in /Applications/MAMP/htdocs/maximus-rev/app/Console/Ker
  3. nel.php on line 57 and exactly 1 expected
  4.  
  5. /**
  6. * Owner Services
  7. *
  8. * @var OwnerServices
  9. */
  10. protected $ownerServices;
  11.  
  12. /**
  13. * Product Services
  14. *
  15. * @var OwnerServices
  16. */
  17. protected $productServices;
  18.  
  19. /**
  20. * Document Services
  21. *
  22. * @var DocumentServices
  23. */
  24. protected $documentServices;
  25.  
  26. /**
  27. * Product Services
  28. *
  29. * @var DocumentProductServices
  30. */
  31. protected $documentProductServices;
  32.  
  33.  
  34.  
  35. public function __construct(OwnerServices $ownerServices, ProductServices $productServices, DocumentServices $documentServices, DocumentProductServices $documentProductServices) {
  36. $this->ownerServices = $ownerServices;
  37. $this->productServices = $productServices;
  38. $this->documentServices = $documentServices;
  39. $this->documentProductServices = $documentProductServices;
  40. }
  41.  
  42. /**
  43. * Funcao responsavel por importar os dados no sistema
  44. *
  45. * @param [type] $request Array que deverá conter a seguinte estrutura:
  46. * $request = [
  47. * 'owner' => [
  48. * 'code' => (string 30) 'Código de Identificacao' (* Obrigatório),
  49. * 'name' => (string 100) 'Nome' (* Obrigatório),
  50. * 'complement', => (string 255) 'Complemento' (Opcional),
  51. * 'document', => (string 14) 'CNPJ' (* Obrigatório)
  52. * ],
  53. * 'document' => [
  54. * 'code' => (string 44) 'Chave Eletronica/Numero Tíquete' (* Obrigatório)
  55. * 'serie' => (string 20) 'Serie NFe' (* Ogriatorio somente para produtos FERRO GUSA)
  56. * 'document_number' => (string 20) 'Numero NFe / Número Tíquete' (* Obrigatório)
  57. * 'observation' => (string MAX) 'Detalhes Adicionais' (Opcional)
  58. * 'content_file' => (string MAX) 'Conteudo do Arquivo Importado' (Opcional)
  59. * ],
  60. * 'product' => [
  61. * 'code' => (string 30) 'Código de Identificacao' (* Obrigatório),
  62. * 'name' => (string 100) 'Nome' (* Obrigatório),
  63. * 'complement' => (string 255) 'Complemento' (Opcional),
  64. * 'amount' => (decimal 5,2) 'Quantidade' (Opcional)
  65. * 'unit_price' => (decimal 10,2) 'Preco Unitario' (Opcional)
  66. * 'gross_weight' => (decimal 5,2) 'Peso Bruto' (Opcional),
  67. * 'net_weight' => (decimal 5,2) 'Peso Liquido' (* Obrigatório),
  68. * 'lot' => (string 20) 'Lote' (* Obrigatorio somente para produtos FERRO GUSA)
  69. * ]
  70. *
  71. * ];
  72. * @return void
  73. */
  74. public function updateOrCreate($request) {
  75.  
  76. IlluminateSupportFacadesLog::info('Services chamado');
  77.  
  78. $lstPrincipal=null;
  79.  
  80. try {
  81.  
  82.  
  83.  
  84. // verifica se existe a tag 'owner'
  85. if(Arr::has($request, 'owner')){
  86.  
  87. // envia para cadastro
  88. $result = $this->ownerServices->updateOrCreate($request['owner']);
  89.  
  90. // verificar se cadastrou corretamente
  91. if($result['success']){
  92. // adiciona ao array principal
  93. $lstPrincipal = Arr::add($lstPrincipal, 'owner_id', $result['data']['id']);
  94. }
  95. }
  96.  
  97. // verifica se existe a tag 'document'
  98. if(Arr::has($request, 'document')){
  99.  
  100. // adiciona a tag 'owner_id' ao array
  101. $temp = Arr::add($request['document'], 'owner_id', $lstPrincipal['owner_id']);
  102.  
  103. // envia para cadastro
  104. $result = $this->documentServices->updateOrCreate($temp);
  105.  
  106. // verificar se cadastrou corretamente
  107. if($result['success']){
  108. // adiciona ao array principal
  109. $lstPrincipal = Arr::add($lstPrincipal, 'document_id', $result['data']['id']);
  110. }
  111. }
  112.  
  113.  
  114. // verifica se existe a 'product'
  115. // adiciona os valores dos produtos da NF
  116. if(Arr::has($request, 'product')){
  117.  
  118. // envia para cadastro
  119. $result = $this->productServices->updateOrCreate($request['product']);
  120.  
  121. // verificar se cadastrou corretamente.
  122. if($result['success']){
  123. // adiciona ao array principal
  124. $lstPrincipal = Arr::add($lstPrincipal, 'product_id', $result['data']['id']);
  125. }
  126.  
  127. // adiciona a tag 'document_id' e 'product_id' ao array
  128. $temp = Arr::add($request['product'], 'product_id', $lstPrincipal['product_id']);
  129. $temp = Arr::add($temp, 'document_id', $lstPrincipal['document_id']);
  130.  
  131. // cadastra os produtos na tabela de produtos da NFe
  132. $dados = $this->documentProductServices->updateOrCreate($temp);
  133.  
  134. }
  135.  
  136. // retorna resultado da gravacao
  137. return [
  138. 'success' => true,
  139. 'message' => 'record created/updated successfully',
  140. 'total' => null,
  141. 'data' => null,
  142. ];
  143. } catch (Throwable $th) {
  144.  
  145. return [
  146. 'success' => false,
  147. 'message' => $th,
  148. 'total' => null,
  149. 'data' => null,
  150. ];
  151. }
  152. }
  153. }
  154.  
  155. class ImportDocumentJob implements ShouldQueue
  156. {
  157. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  158.  
  159. protected $services;
  160. public function __construct(ImportDocumentsServices $services)
  161. {
  162. $this->services = $services;
  163. }
  164.  
  165. /**
  166. * Execute the job.
  167. *
  168. * @return void
  169. */
  170. public function handle()
  171. {
  172.  
  173.  
  174. $lst = IlluminateSupportFacadesFile::allFiles(storage_path('app/xml/'));
  175.  
  176. $dados=null;
  177. foreach ($lst as $key => $value) {
  178.  
  179. $fullPath = (string)$value;
  180.  
  181. // verifica somente arquivos com extensao xml
  182. if(File::extension($fullPath) == 'xml') {
  183. // carrega o arquivo xml
  184. $xml = simplexml_load_file($fullPath);
  185.  
  186. // verifica se o documento é um XMl de NFE
  187. if(isset($xml->NFe)) {
  188.  
  189. // montagem do array para cadastro
  190. $request = [
  191. 'owner' => [
  192. 'code' => (string)$xml->NFe->infNFe->emit->CNPJ,
  193. 'name' => (string)$xml->NFe->infNFe->emit->xNome,
  194. 'complement' => (string)$xml->NFe->infNFe->emit->xFant,
  195. 'document' => (string)$xml->NFe->infNFe->emit->CNPJ
  196. ],
  197. 'document' => [
  198. 'code' => str_replace("NFe","",(string)$xml->NFe->infNFe->attributes()->Id),
  199. 'serie' => (string)$xml->NFe->infNFe->ide->serie,
  200. 'document_number' => (string)$xml->NFe->infNFe->ide->cNF,
  201. 'observation' => (string)$xml->NFe->infNFe->infAdic->infCpl,
  202. 'content_file' => file_get_contents($fullPath),
  203. ],
  204. 'product' => [
  205. 'code' => (string)$xml->NFe->infNFe->det->prod->cProd,
  206. 'name' => (string)$xml->NFe->infNFe->det->prod->xProd,
  207. 'complement' => null,
  208. 'amount' => null,
  209. 'unit_price' => null,
  210. 'gross_weight' => null,
  211. 'net_weight' => (floatval((string)$xml->NFe->infNFe->det->prod->qCom)*1000),
  212. 'lot' => (string)$xml->NFe->infNFe->transp->vol->marca
  213. ]
  214. ];
  215.  
  216. $this->services->updateOrCreate($request);
  217.  
  218. }
  219. }
  220. }
  221. }
  222. }
  223.  
  224. class Kernel extends ConsoleKernel
  225. {
  226. /**
  227. * The Artisan commands provided by your application.
  228. *
  229. * @var array
  230. */
  231. protected $commands = [
  232. //
  233. ];
  234.  
  235. /**
  236. * Define the application's command schedule.
  237. *
  238. * @param IlluminateConsoleSchedulingSchedule $schedule
  239. * @return void
  240. */
  241. protected function schedule(Schedule $schedule)
  242. {
  243.  
  244.  
  245.  
  246.  
  247.  
  248. // Importacao automatica de arquivos XML
  249. $schedule->job(new AppJobsImportDocumentJob)->everyMinute();
  250.  
  251. // $schedule->command('inspire')
  252. // ->hourly();
  253. }
  254.  
  255. /**
  256. * Register the commands for the application.
  257. *
  258. * @return void
  259. */
  260. protected function commands()
  261. {
  262. $this->load(__DIR__.'/Commands');
  263.  
  264. require base_path('routes/console.php');
  265. }
  266. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement