2022-01-13 01:19:13 -08:00
< ? php
2024-05-29 12:07:48 -07:00
namespace App\Livewire ;
2022-01-13 01:19:13 -08:00
2023-03-18 20:31:56 -07:00
use App\Models\CustomField ;
2022-01-13 01:19:13 -08:00
use Livewire\Component ;
use App\Models\Import ;
2024-05-29 04:53:51 -07:00
use Illuminate\Support\Facades\Storage ;
2022-01-13 01:19:13 -08:00
2023-02-28 21:58:02 -08:00
use Illuminate\Foundation\Auth\Access\AuthorizesRequests ;
2022-01-13 01:19:13 -08:00
class Importer extends Component
{
2023-02-28 21:58:02 -08:00
use AuthorizesRequests ;
2022-01-13 01:19:13 -08:00
public $files ;
2022-09-19 21:04:46 -07:00
public $progress ; //upload progress - '-1' means don't show
2023-03-21 22:26:32 -07:00
public $progress_message ;
2022-09-19 21:04:46 -07:00
public $progress_bar_class ;
public $message ; //status/error message?
public $message_type ; //success/error?
2023-03-18 20:31:56 -07:00
//originally from ImporterFile
2022-12-14 10:55:50 -08:00
public $import_errors ; //
2023-03-21 22:26:32 -07:00
public ? Import $activeFile = null ;
2023-03-18 20:31:56 -07:00
public $importTypes ;
public $columnOptions ;
public $statusType ;
public $statusText ;
public $update ;
public $send_welcome ;
public $run_backup ;
public $field_map ; // we need a separate variable for the field-mapping, because the keys in the normal array are too complicated for Livewire to understand
2023-03-21 22:26:32 -07:00
public $file_id ; // TODO: I can't figure out *why* we need this, but it really seems like we do. I can't seem to pull the id from the activeFile for some reason?
2022-12-14 10:55:50 -08:00
2023-05-16 22:31:58 -07:00
// Make these variables public - we set the properties in the constructor so we can localize them (versus the old static arrays)
public $accessories_fields ;
2023-06-07 07:52:18 -07:00
public $assets_fields ;
2023-05-16 22:31:58 -07:00
public $users_fields ;
public $licenses_fields ;
public $locations_fields ;
public $consumables_fields ;
public $components_fields ;
public $aliases_fields ;
2022-01-13 01:19:13 -08:00
protected $rules = [
'files.*.file_path' => 'required|string' ,
'files.*.created_at' => 'required|string' ,
2023-03-18 20:31:56 -07:00
'files.*.filesize' => 'required|integer' ,
2023-03-21 22:26:32 -07:00
'activeFile' => 'Import' ,
2023-03-18 20:31:56 -07:00
'activeFile.import_type' => 'string' ,
'activeFile.field_map' => 'array' ,
'activeFile.header_row' => 'array' ,
'field_map' => 'array'
2022-01-13 01:19:13 -08:00
];
2024-02-22 10:28:01 -08:00
/**
2024-05-29 12:07:48 -07:00
* This is used in resources / views / livewire . importer . blade . php , and we kinda shouldn ' t need to check for
2024-02-22 10:28:01 -08:00
* activeFile here , but there ' s some UI goofiness that allows this to crash out on some imports .
*
2024-02-22 10:30:23 -08:00
* @ return string
2024-02-22 10:28:01 -08:00
*/
2023-03-18 20:31:56 -07:00
public function generate_field_map ()
{
2024-02-22 10:28:01 -08:00
$tmp = array ();
if ( $this -> activeFile ) {
$tmp = array_combine ( $this -> activeFile -> header_row , $this -> field_map );
2024-02-22 10:31:02 -08:00
$tmp = array_filter ( $tmp );
2024-02-22 10:28:01 -08:00
}
return json_encode ( $tmp );
2023-03-18 20:31:56 -07:00
}
private function getColumns ( $type )
{
2024-08-16 18:31:03 -07:00
\Log :: error ( $type );
2023-03-21 22:26:32 -07:00
switch ( $type ) {
2023-03-18 20:31:56 -07:00
case 'asset' :
2023-05-23 20:31:53 -07:00
$results = $this -> assets_fields ;
2023-03-18 20:31:56 -07:00
break ;
case 'accessory' :
2023-05-23 20:31:53 -07:00
$results = $this -> accessories_fields ;
2023-03-18 20:31:56 -07:00
break ;
case 'consumable' :
2023-05-23 20:31:53 -07:00
$results = $this -> consumables_fields ;
2023-03-18 20:31:56 -07:00
break ;
2023-05-20 14:20:49 -07:00
case 'component' :
2023-05-23 20:31:53 -07:00
$results = $this -> components_fields ;
2023-05-20 14:20:49 -07:00
break ;
2023-03-18 20:31:56 -07:00
case 'license' :
2023-05-23 20:31:53 -07:00
$results = $this -> licenses_fields ;
2023-03-18 20:31:56 -07:00
break ;
case 'user' :
2023-05-23 20:31:53 -07:00
$results = $this -> users_fields ;
2023-03-18 20:31:56 -07:00
break ;
2023-04-16 07:47:42 -07:00
case 'location' :
2023-05-23 20:31:53 -07:00
$results = $this -> locations_fields ;
2023-04-16 07:47:42 -07:00
break ;
2024-08-16 18:31:03 -07:00
case 'assetmodel' :
$results = $this -> assetmodels_fields ;
break ;
2023-03-18 20:31:56 -07:00
default :
2023-05-23 20:31:53 -07:00
$results = [];
2023-03-18 20:31:56 -07:00
}
2023-03-21 22:26:32 -07:00
asort ( $results , SORT_FLAG_CASE | SORT_STRING );
2024-08-16 18:31:03 -07:00
2023-03-21 22:26:32 -07:00
if ( $type == " asset " ) {
2023-03-18 20:31:56 -07:00
// add Custom Fields after a horizontal line
2023-03-21 22:26:32 -07:00
$results [ '-' ] = " ——— " . trans ( 'admin/custom_fields/general.custom_fields' ) . " ———’ " ;
foreach ( CustomField :: orderBy ( 'name' ) -> get () as $field ) {
2023-03-18 20:31:56 -07:00
$results [ $field -> db_column_name ()] = $field -> name ;
}
}
return $results ;
}
public function updating ( $name , $new_import_type )
{
if ( $name == " activeFile.import_type " ) {
2024-05-30 15:03:04 -07:00
2023-03-18 20:31:56 -07:00
// go through each header, find a matching field to try and map it to.
2023-03-21 22:26:32 -07:00
foreach ( $this -> activeFile -> header_row as $i => $header ) {
2023-03-18 20:31:56 -07:00
// do we have something mapped already?
if ( array_key_exists ( $i , $this -> field_map )) {
// yes, we do. Is it valid for this type of import?
// (e.g. the import type might have been changed...?)
if ( array_key_exists ( $this -> field_map [ $i ], $this -> columnOptions [ $new_import_type ])) {
//yes, this key *is* valid. Continue on to the next field.
continue ;
} else {
//no, this key is *INVALID* for this import type. Better set it to null
2023-05-16 22:31:58 -07:00
// and we'll hope that the $aliases_fields or something else picks it up.
2023-03-18 20:31:56 -07:00
$this -> field_map [ $i ] = null ; // fingers crossed! But it's not likely, tbh.
} // TODO - strictly speaking, this isn't necessary here I don't think.
}
// first, check for exact matches
2023-03-21 22:26:32 -07:00
foreach ( $this -> columnOptions [ $new_import_type ] as $value => $text ) {
2023-03-18 20:31:56 -07:00
if ( strcasecmp ( $text , $header ) === 0 ) { // case-INSENSITIVe on purpose!
$this -> field_map [ $i ] = $value ;
continue 2 ; //don't bother with the alias check, go to the next header
}
}
2023-05-16 22:31:58 -07:00
// if you got here, we didn't find a match. Try the $aliases_fields
foreach ( $this -> aliases_fields as $key => $alias_values ) {
2024-08-16 18:31:03 -07:00
\Log :: error ( 'No matches' );
2023-03-21 22:26:32 -07:00
foreach ( $alias_values as $alias_value ) {
if ( strcasecmp ( $alias_value , $header ) === 0 ) { // aLsO CaSe-INSENSitiVE!
2023-03-18 20:31:56 -07:00
// Make *absolutely* sure that this key actually _exists_ in this import type -
// you can trigger this by importing accessories with a 'Warranty' column (which don't exist
// in "Accessories"!)
if ( array_key_exists ( $key , $this -> columnOptions [ $new_import_type ])) {
$this -> field_map [ $i ] = $key ;
continue 3 ; // bust out of both of these loops; as well as the surrounding one - e.g. move on to the next header
}
}
}
}
// and if you got here, we got nothing. Let's recommend 'null'
$this -> field_map [ $i ] = null ; // Booooo :(
}
}
}
2023-03-21 22:26:32 -07:00
public function boot () { // FIXME - delete or undelete.
///////$this->activeFile = null; // I do *not* understand why I have to do this, but, well, whatever.
}
2023-03-18 20:31:56 -07:00
2022-01-13 01:19:13 -08:00
public function mount ()
{
2023-02-28 21:58:02 -08:00
$this -> authorize ( 'import' );
2022-09-19 21:04:46 -07:00
$this -> progress = - 1 ; // '-1' means 'don't show the progressbar'
$this -> progress_bar_class = 'progress-bar-warning' ;
2023-03-18 20:31:56 -07:00
$this -> importTypes = [
2024-08-16 18:31:03 -07:00
'asset' => trans ( 'general.assets' ),
'accessory' => trans ( 'general.accessories' ),
'consumable' => trans ( 'general.consumables' ),
'component' => trans ( 'general.components' ),
'license' => trans ( 'general.licenses' ),
'user' => trans ( 'general.users' ),
'location' => trans ( 'general.locations' ),
'assetmodel' => trans ( 'general.asset_models' ),
2023-03-18 20:31:56 -07:00
];
2023-05-23 20:31:53 -07:00
/**
* These are the item - type specific columns
*/
$this -> accessories_fields = [
2023-05-16 22:31:58 -07:00
'company' => trans ( 'general.company' ),
'location' => trans ( 'general.location' ),
'quantity' => trans ( 'general.qty' ),
2023-05-20 14:21:13 -07:00
'item_name' => trans ( 'general.item_name_var' , [ 'item' => trans ( 'general.accessory' )]),
'model_number' => trans ( 'general.model_no' ),
2023-05-16 22:31:58 -07:00
'notes' => trans ( 'general.notes' ),
'category' => trans ( 'general.category' ),
'supplier' => trans ( 'general.supplier' ),
2023-05-20 14:21:13 -07:00
'min_amt' => trans ( 'mail.min_QTY' ),
2023-05-16 22:31:58 -07:00
'purchase_cost' => trans ( 'general.purchase_cost' ),
'purchase_date' => trans ( 'general.purchase_date' ),
'manufacturer' => trans ( 'general.manufacturer' ),
2023-05-23 12:13:06 -07:00
'order_number' => trans ( 'general.order_number' ),
2023-05-16 22:31:58 -07:00
];
$this -> assets_fields = [
2023-05-23 20:31:53 -07:00
'company' => trans ( 'general.company' ),
'location' => trans ( 'general.location' ),
2023-05-20 14:21:13 -07:00
'item_name' => trans ( 'general.item_name_var' , [ 'item' => trans ( 'general.asset' )]),
2023-05-16 22:31:58 -07:00
'asset_tag' => trans ( 'general.asset_tag' ),
'asset_model' => trans ( 'general.model_name' ),
'byod' => trans ( 'general.byod' ),
2023-05-20 14:21:13 -07:00
'model_number' => trans ( 'general.model_no' ),
2023-05-16 22:31:58 -07:00
'status' => trans ( 'general.status' ),
2023-05-20 14:21:13 -07:00
'warranty_months' => trans ( 'admin/hardware/form.warranty' ),
2023-05-16 22:31:58 -07:00
'category' => trans ( 'general.category' ),
2023-05-20 14:21:13 -07:00
'requestable' => trans ( 'admin/hardware/general.requestable' ),
'serial' => trans ( 'general.serial_number' ),
2023-05-16 22:31:58 -07:00
'supplier' => trans ( 'general.supplier' ),
'purchase_cost' => trans ( 'general.purchase_cost' ),
'purchase_date' => trans ( 'general.purchase_date' ),
2023-05-20 14:21:13 -07:00
'purchase_order' => trans ( 'admin/licenses/form.purchase_order' ),
'asset_notes' => trans ( 'general.item_notes' , [ 'item' => trans ( 'admin/hardware/general.asset' )]),
'model_notes' => trans ( 'general.item_notes' , [ 'item' => trans ( 'admin/hardware/form.model' )]),
2023-05-16 22:31:58 -07:00
'manufacturer' => trans ( 'general.manufacturer' ),
2023-05-23 12:13:06 -07:00
'order_number' => trans ( 'general.order_number' ),
2023-05-23 12:57:34 -07:00
'image' => trans ( 'general.importer.image_filename' ),
2023-08-08 09:45:33 -07:00
'asset_eol_date' => trans ( 'admin/hardware/form.eol_date' ),
2023-05-23 19:20:52 -07:00
/**
* Checkout fields :
* Assets can be checked out to other assets , people , or locations , but we currently
* only support checkout to people and locations in the importer
**/
2023-05-23 12:57:34 -07:00
'checkout_class' => trans ( 'general.importer.checkout_type' ),
'first_name' => trans ( 'general.importer.checked_out_to_first_name' ),
'last_name' => trans ( 'general.importer.checked_out_to_last_name' ),
'full_name' => trans ( 'general.importer.checked_out_to_fullname' ),
'email' => trans ( 'general.importer.checked_out_to_email' ),
'username' => trans ( 'general.importer.checked_out_to_username' ),
'checkout_location' => trans ( 'general.importer.checkout_location' ),
2024-05-30 16:13:20 -07:00
/**
* These are here so users can import history , to replace the dinosaur that
* was the history importer
*/
'last_checkin' => trans ( 'admin/hardware/table.last_checkin_date' ),
'last_checkout' => trans ( 'admin/hardware/table.checkout_date' ),
'expected_checkin' => trans ( 'admin/hardware/form.expected_checkin' ),
'last_audit_date' => trans ( 'general.last_audit' ),
'next_audit_date' => trans ( 'general.next_audit_date' ),
2023-05-16 22:31:58 -07:00
];
$this -> consumables_fields = [
2023-05-23 20:31:53 -07:00
'company' => trans ( 'general.company' ),
'location' => trans ( 'general.location' ),
'quantity' => trans ( 'general.qty' ),
2023-05-20 14:21:13 -07:00
'item_name' => trans ( 'general.item_name_var' , [ 'item' => trans ( 'general.consumable' )]),
'model_number' => trans ( 'general.model_no' ),
2023-05-16 22:31:58 -07:00
'notes' => trans ( 'general.notes' ),
2023-05-20 14:21:13 -07:00
'min_amt' => trans ( 'mail.min_QTY' ),
2023-05-16 22:31:58 -07:00
'category' => trans ( 'general.category' ),
'purchase_cost' => trans ( 'general.purchase_cost' ),
'purchase_date' => trans ( 'general.purchase_date' ),
2023-05-20 14:21:13 -07:00
'checkout_class' => trans ( 'general.importer.checkout_type' ),
2023-05-16 22:31:58 -07:00
'supplier' => trans ( 'general.supplier' ),
2023-05-23 12:13:06 -07:00
'manufacturer' => trans ( 'general.manufacturer' ),
'order_number' => trans ( 'general.order_number' ),
'item_no' => trans ( 'admin/consumables/general.item_no' ),
2023-05-16 22:31:58 -07:00
];
$this -> components_fields = [
2023-05-23 20:31:53 -07:00
'company' => trans ( 'general.company' ),
'location' => trans ( 'general.location' ),
'quantity' => trans ( 'general.qty' ),
2023-05-20 14:21:13 -07:00
'item_name' => trans ( 'general.item_name_var' , [ 'item' => trans ( 'general.component' )]),
'model_number' => trans ( 'general.model_no' ),
2023-05-16 22:31:58 -07:00
'notes' => trans ( 'general.notes' ),
'category' => trans ( 'general.category' ),
'supplier' => trans ( 'general.supplier' ),
2023-05-20 14:21:13 -07:00
'min_amt' => trans ( 'mail.min_QTY' ),
2023-05-16 22:31:58 -07:00
'purchase_cost' => trans ( 'general.purchase_cost' ),
'purchase_date' => trans ( 'general.purchase_date' ),
2023-05-23 12:13:06 -07:00
'manufacturer' => trans ( 'general.manufacturer' ),
'order_number' => trans ( 'general.order_number' ),
'serial' => trans ( 'general.serial_number' ),
2023-05-16 22:31:58 -07:00
];
$this -> licenses_fields = [
2023-05-23 20:31:53 -07:00
'company' => trans ( 'general.company' ),
'location' => trans ( 'general.location' ),
2023-05-20 14:21:13 -07:00
'item_name' => trans ( 'general.item_name_var' , [ 'item' => trans ( 'general.license' )]),
2023-06-01 11:51:06 -07:00
'asset_tag' => trans ( 'general.importer.checked_out_to_tag' ),
'expiration_date' => trans ( 'admin/licenses/form.expiration' ),
'full_name' => trans ( 'general.importer.checked_out_to_fullname' ),
'license_email' => trans ( 'admin/licenses/form.to_email' ),
'license_name' => trans ( 'admin/licenses/form.to_name' ),
'purchase_order' => trans ( 'admin/licenses/form.purchase_order' ),
2023-09-28 06:24:07 -07:00
'order_number' => trans ( 'general.order_number' ),
2023-05-20 14:21:13 -07:00
'reassignable' => trans ( 'admin/licenses/form.reassignable' ),
2023-06-01 11:51:06 -07:00
'seats' => trans ( 'admin/licenses/form.seats' ),
2023-05-16 22:31:58 -07:00
'notes' => trans ( 'general.notes' ),
'category' => trans ( 'general.category' ),
'supplier' => trans ( 'general.supplier' ),
'purchase_cost' => trans ( 'general.purchase_cost' ),
'purchase_date' => trans ( 'general.purchase_date' ),
2023-06-01 11:51:06 -07:00
'maintained' => trans ( 'admin/licenses/form.maintained' ),
2023-05-20 14:21:13 -07:00
'checkout_class' => trans ( 'general.importer.checkout_type' ),
'serial' => trans ( 'general.license_serial' ),
2023-07-06 17:36:13 -07:00
'email' => trans ( 'general.importer.checked_out_to_email' ),
'username' => trans ( 'general.importer.checked_out_to_username' ),
2023-07-20 05:48:51 -07:00
'manufacturer' => trans ( 'general.manufacturer' ),
2023-05-16 22:31:58 -07:00
];
$this -> users_fields = [
2023-06-15 02:02:05 -07:00
'id' => trans ( 'general.id' ),
2023-05-23 20:31:53 -07:00
'company' => trans ( 'general.company' ),
'location' => trans ( 'general.location' ),
'department' => trans ( 'general.department' ),
2023-05-16 22:31:58 -07:00
'first_name' => trans ( 'general.first_name' ),
'last_name' => trans ( 'general.last_name' ),
'notes' => trans ( 'general.notes' ),
2023-05-20 14:52:42 -07:00
'username' => trans ( 'admin/users/table.username' ),
'jobtitle' => trans ( 'admin/users/table.title' ),
'phone_number' => trans ( 'admin/users/table.phone' ),
2023-05-20 14:21:13 -07:00
'manager_first_name' => trans ( 'general.importer.manager_first_name' ),
'manager_last_name' => trans ( 'general.importer.manager_last_name' ),
2023-05-16 22:31:58 -07:00
'activated' => trans ( 'general.activated' ),
'address' => trans ( 'general.address' ),
'city' => trans ( 'general.city' ),
'state' => trans ( 'general.state' ),
'country' => trans ( 'general.country' ),
'zip' => trans ( 'general.zip' ),
2023-05-20 14:52:42 -07:00
'vip' => trans ( 'general.importer.vip' ),
'remote' => trans ( 'admin/users/general.remote' ),
'email' => trans ( 'admin/users/table.email' ),
2023-05-22 13:20:08 -07:00
'website' => trans ( 'general.website' ),
2023-05-20 14:52:42 -07:00
'avatar' => trans ( 'general.image' ),
2023-05-22 13:20:08 -07:00
'gravatar' => trans ( 'general.importer.gravatar' ),
'start_date' => trans ( 'general.start_date' ),
'end_date' => trans ( 'general.end_date' ),
2023-07-17 11:08:10 -07:00
'employee_num' => trans ( 'general.employee_number' ),
2023-05-16 22:31:58 -07:00
];
$this -> locations_fields = [
2023-05-20 14:52:42 -07:00
'name' => trans ( 'general.item_name_var' , [ 'item' => trans ( 'general.location' )]),
2023-05-16 22:31:58 -07:00
'address' => trans ( 'general.address' ),
2023-05-20 14:52:42 -07:00
'address2' => trans ( 'general.importer.address2' ),
2023-05-16 22:31:58 -07:00
'city' => trans ( 'general.city' ),
'state' => trans ( 'general.state' ),
'country' => trans ( 'general.country' ),
'zip' => trans ( 'general.zip' ),
2023-05-20 14:52:42 -07:00
'currency' => trans ( 'general.importer.currency' ),
'ldap_ou' => trans ( 'admin/locations/table.ldap_ou' ),
'manager_username' => trans ( 'general.importer.manager_username' ),
'manager' => trans ( 'general.importer.manager_full_name' ),
'parent_location' => trans ( 'admin/locations/table.parent' ),
2023-05-16 22:31:58 -07:00
];
2024-08-16 18:31:03 -07:00
$this -> assetmodels_fields = [
'item_name' => trans ( 'general.item_name_var' , [ 'item' => trans ( 'general.asset_model' )]),
'category' => trans ( 'general.category' ),
'manufacturer' => trans ( 'general.manufacturer' ),
'model_number' => trans ( 'general.model_no' ),
'notes' => trans ( 'general.item_notes' , [ 'item' => trans ( 'admin/hardware/form.model' )]),
'min_amt' => trans ( 'mail.min_QTY' ),
'fieldset' => trans ( 'admin/models/general.fieldset' ),
'category_type' => 'category type' ,
];
2023-05-16 22:31:58 -07:00
// "real fieldnames" to a list of aliases for that field
$this -> aliases_fields = [
2023-05-20 14:21:13 -07:00
'item_name' =>
[
2023-05-23 12:13:06 -07:00
'item name' ,
'asset name' ,
'accessory name' ,
'user name' ,
'consumable name' ,
'component name' ,
2023-05-20 14:52:42 -07:00
'name' ,
2023-05-20 14:21:13 -07:00
],
2023-05-23 12:13:06 -07:00
'item_no' => [
'item number' ,
'item no.' ,
'item #' ,
],
'asset_model' =>
2023-05-20 14:21:13 -07:00
[
'model name' ,
2023-05-23 12:13:06 -07:00
'model' ,
2023-05-20 14:21:13 -07:00
],
2024-08-16 12:29:53 -07:00
'eol_date' =>
[
'eol' ,
'eol date' ,
'asset eol date' ,
],
2023-05-22 13:20:08 -07:00
'gravatar' =>
[
'gravatar' ,
],
2023-05-20 14:52:42 -07:00
'currency' =>
[
'$' ,
],
'jobtitle' =>
[
'job title for user' ,
2023-05-22 13:20:08 -07:00
'job title' ,
2023-05-20 14:52:42 -07:00
],
2024-05-30 16:13:20 -07:00
'full_name' =>
[
'full name' ,
'fullname' ,
trans ( 'general.importer.checked_out_to_fullname' )
],
2023-05-20 14:52:42 -07:00
'username' =>
[
'user name' ,
2023-05-23 13:18:32 -07:00
'username' ,
trans ( 'general.importer.checked_out_to_username' ),
],
'first_name' =>
[
'first name' ,
trans ( 'general.importer.checked_out_to_first_name' ),
],
'last_name' =>
[
'last name' ,
'lastname' ,
trans ( 'general.importer.checked_out_to_last_name' ),
],
'email' =>
[
'email' ,
'e-mail' ,
trans ( 'general.importer.checked_out_to_email' ),
2023-05-20 14:52:42 -07:00
],
'phone_number' =>
[
'phone' ,
'phone number' ,
'phone num' ,
'telephone number' ,
'telephone' ,
'tel.' ,
],
2024-05-30 16:13:20 -07:00
2023-05-20 14:21:13 -07:00
'serial' =>
[
'serial number' ,
'serial no.' ,
'serial no' ,
'product key' ,
'key' ,
],
2023-05-16 22:31:58 -07:00
'model_number' =>
[
'model' ,
'model no' ,
'model no.' ,
'model number' ,
'model num' ,
'model num.'
],
'warranty_months' =>
[
'Warranty' ,
'Warranty Months'
],
'qty' =>
[
'QTY' ,
'Quantity'
],
'zip' =>
[
'Postal Code' ,
2023-05-20 14:21:13 -07:00
'Post Code' ,
'Zip Code'
2023-05-16 22:31:58 -07:00
],
'min_amt' =>
[
'Min Amount' ,
2023-05-23 12:13:06 -07:00
'Minimum Amount' ,
'Min Quantity' ,
'Minimum Quantity' ,
2023-05-16 22:31:58 -07:00
],
'next_audit_date' =>
[
'Next Audit' ,
],
2024-05-30 16:13:20 -07:00
'last_checkout' =>
[
'Last Checkout' ,
'Last Checkout Date' ,
'Checkout Date' ,
],
2023-05-16 22:31:58 -07:00
'address2' =>
[
'Address 2' ,
'Address2' ,
],
'ldap_ou' =>
[
'LDAP OU' ,
'OU' ,
],
'parent_location' =>
[
'Parent' ,
'Parent Location' ,
],
'manager' =>
[
'Managed By' ,
'Manager Name' ,
'Manager Full Name' ,
],
'manager_username' =>
[
'Manager Username' ,
],
];
2023-03-18 20:31:56 -07:00
$this -> columnOptions [ '' ] = $this -> getColumns ( '' ); //blank mode? I don't know what this is supposed to mean
foreach ( $this -> importTypes AS $type => $name ) {
$this -> columnOptions [ $type ] = $this -> getColumns ( $type );
}
if ( $this -> activeFile ) {
$this -> field_map = $this -> activeFile -> field_map ? array_values ( $this -> activeFile -> field_map ) : [];
}
2022-01-13 01:19:13 -08:00
}
2023-03-21 22:26:32 -07:00
public function selectFile ( $id )
2023-02-28 18:36:52 -08:00
{
2023-09-20 17:22:12 -07:00
$this -> clearMessage ();
2023-04-16 07:47:42 -07:00
2023-03-21 22:26:32 -07:00
$this -> activeFile = Import :: find ( $id );
2023-09-20 17:22:12 -07:00
if ( ! $this -> activeFile ) {
2023-09-20 17:35:34 -07:00
$this -> message = trans ( 'admin/hardware/message.import.file_missing' );
$this -> message_type = 'danger' ;
return ;
2023-09-20 17:22:12 -07:00
}
2023-03-21 22:26:32 -07:00
$this -> field_map = null ;
foreach ( $this -> activeFile -> header_row as $element ) {
2024-08-16 18:31:03 -07:00
2023-03-21 22:26:32 -07:00
if ( isset ( $this -> activeFile -> field_map [ $element ])) {
$this -> field_map [] = $this -> activeFile -> field_map [ $element ];
} else {
$this -> field_map [] = null ; // re-inject the 'nulls' if a file was imported with some 'Do Not Import' settings
}
}
2024-08-16 18:31:03 -07:00
2023-03-21 22:26:32 -07:00
$this -> file_id = $id ;
$this -> import_errors = null ;
$this -> statusText = null ;
2022-01-13 01:19:13 -08:00
2022-11-22 12:41:25 -08:00
}
2022-09-19 21:04:46 -07:00
public function destroy ( $id )
{
2023-03-21 22:26:32 -07:00
// TODO: why don't we just do File::find($id)? This seems dumb.
2022-09-19 21:04:46 -07:00
foreach ( $this -> files as $file ) {
2024-05-30 16:13:20 -07:00
if ( $id == $file -> id ) {
if ( Storage :: delete ( 'private_uploads/imports/' . $file -> file_path )) {
2023-02-28 22:34:44 -08:00
$file -> delete ();
$this -> message = trans ( 'admin/hardware/message.import.file_delete_success' );
$this -> message_type = 'success' ;
return ;
} else {
$this -> message = trans ( 'admin/hardware/message.import.file_delete_error' );
$this -> message_type = 'danger' ;
}
2022-09-19 21:04:46 -07:00
}
}
}
2023-09-20 17:22:12 -07:00
public function clearMessage ()
{
$this -> message = null ;
$this -> message_type = null ;
}
2022-01-13 01:19:13 -08:00
public function render ()
{
2022-09-19 21:04:46 -07:00
$this -> files = Import :: orderBy ( 'id' , 'desc' ) -> get (); //HACK - slows down renders.
2024-05-29 12:57:43 -07:00
return view ( 'livewire.importer' )
2023-02-28 18:36:52 -08:00
-> extends ( 'layouts.default' )
2023-02-28 21:58:02 -08:00
-> section ( 'content' );
2022-01-13 01:19:13 -08:00
}
}