How do I create data in PHP code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lj4353
    Senior Member
    • Nov 2023
    • 114

    How do I create data in PHP code?

    I added a button to create payrolls in the attendance sheet, and I hope to achieve the following effects. I would be very grateful if you could give me some reference examples:

    I am currently able to get the selected object, but I do not know how to create a payroll.
    console.log(item.attributes.dateOfWork);
    console.log(item.attributes.assignedUserId);
    1. Select the attendance object.
    2. Click to create the payroll.
    3. Create the payroll."
    HTML Code:
    define('custom:views/Employeework/list', 'views/list', function (Dep) {
    
    return Dep.extend({
    
    setup: function() {
    Dep.prototype.setup.call(this);
    this.setupCustomButtons();
    },
    
    setupCustomButtons: function () {
    this.menu.buttons.push({
    action: 'myAction',
    html: '<span class="fas fa-comment-dollar fa-sm"></span> ' + this.translate('Create Employeewages', 'labels', this.scope),
    style: 'default',
    acl: 'create', // Change 'read' to 'create'
    aclScope: this.entityType || this.scope
    });
    },
    
    actionMyAction: function() {
    var selectedItems = this.getSelected();
    if (!selectedItems.length) {
    Espo.Ui.warning(this.translate('请选择出勤对象', 'Employeework'));
    return;
    } else {
    selectedItems.forEach(function(item) {
    console.log(item);
    console.log(item.attributes.dateOfWork);
    console.log(item.attributes.assignedUserId);
    //corresponding payroll entries
    // employeework = new Employeework();
    // Assuming Employeewages is a model, create a new instance
    // employeework = item.assignedUserId;
    // dateOfWork = item.dateOfWork;
    // Perform any necessary operations with employeewages object here
    // console.log(employeewages);
    }, this);
    }
    },
    
    /**
    * Get selected models.
    *
    * @return {module:model[]}
    */
    getSelected() {
    const list = [];
    
    this.$el.find('input.record-checkbox:checked').each((i, el) => {
    const id = $(el).attr('data-id');
    const model = this.collection.get(id);
    
    list.push(model);
    });
    
    return list;
    }
    });
    });​
    Click image for larger version  Name:	image.png Views:	0 Size:	108.0 KB ID:	103017
    Last edited by lj4353; 02-23-2024, 10:26 AM.
  • radek
    Junior Member
    • Feb 2024
    • 8

    #2
    There are 2 approaches you can take

    1) back end api action
    - make api action that receives the selected IDs as post body and creates payroll records through entity manager
    2) frontend conversion
    - you can redirect the user to a create form and prefill data to it, but I am not sure if it's correct for this situation where you have multiple records selected, it depends on the entity design - does user need to fill in additional data while creating the records? If yes then this is the way to go

    Comment

    Working...