Choose time slot before provider on Appointments

Hello,
I'm a new premium user of Appointments. I'm french so sorry for the mistakes
I'm coming here cause David helped me a lot on the Wordpress support forum.
(http://goo.gl/jKu2w1)
He created a great code to have a random choice of the staff. if someone needs it, it's: [app_random_service_providers].

I really need another custom code. Without this my business can't work:
I saw on this support website that another guy asked for the same thing 2 years ago (http://goo.gl/VBtn7l). I added a new question but it looks like nobody look at this old topic. That's why i'm opening this new one. I tried to contact the Original Poster ("scdwb") but i don't know how to do...

He explained the need very well so i just copy/past:

This is a question about the booking process on the Appointments+ plugin.

At the moment the process is:

1. Select Service
2. Select Service Provider
3. Select day and time slot

The process I need is to select the service provider after selecting the time slot. So instead:

1. Select Service
2. Select day and time slot
3. Select Service Provider

[...]
Then obviously at this point the only providers that users will have the option to select would be those that are available for the "Service" and "time slot" previously selected.

So, could someone tell me if i can expect to find a solution? or maybe... how could i contact "scdwb" to ask him how he did?

Thank you very much

  • Ivan

    Hey Mathieu,

    Welcome to the WPMU DEV Community!

    For me your english is perfect, so no need to apologize. :slight_smile:

    If I understand you correctly you don't want to use the code for the random providers posted here.
    I just want the Service Provider to be the last to choose?

    I would really love to just post a code here that will work for you, but unfortunately this is a little bit more than I can do.

    You can always post a job on our job board, or choose a developer to do it for you.

    I will flag our SLS(Second Level Support) to see if they can help you with this. Please note that they are pretty busy with more complex problems than me, and it might take little longer for them to respond.

    Have a great Sunday!
    Ivan

  • Mathieu

    Hi,
    thank you for your quick answer. I feel good to know that you're so "reactive"
    so,
    It's not that i don't want to use this code. I'll need this code but in a second time.

    I need that the client, when he wants to book, chooses FIRST the service, then, in SECOND, the time slot.
    The client must not choose his provider. The provider choice must be done automaticly and randomly with the available providers. this can be "hidden". the client will just know who is the provider while he'll receive the email notification.

    I hope i've been clear
    Thanks
    Mathieu

  • Ivan

    Hello Mathieu,

    Sorry for the delay on your question.

    I played a little with the code provided by Vinod in the thread here.

    Unfortunately I wasn't able to hide neither the calendar or the service provider selection. The way Appointments+ works doesn't allow the calendar or the service provider to be hidden.

    If I hide the service provider dropdown no provider is selected, and the appointments doesn't get assigned to anyone, just "Our Staff".

    The only thing I was able to do is to make the service providers dropdown inactive, you can use the updated code here - http://pastebin.com/8Rj4J9xw

    I will invite @Vinod Dalvi to the thread if can advise somehow.

    Thanks,
    Ivan

  • Mathieu

    Hi,
    thank you for your answer

    If I hide the service provider dropdown no provider is selected, and the appointments doesn't get assigned to anyone, just "Our Staff".

    Yes, i know, i tried this. If i do this, it means that, once the client booked, i have to manually give the job to one of the provider. This is not possible cause it's not efficient.

    The only thing I was able to do is to make the service providers dropdown inactive, you can use the updated code here - http://pastebin.com/8Rj4J9xw

    Well, thank you.
    I'm not sur this is what i need but i wanted to try.
    So.... i copied the texte and paste it with my "snippets" plugin. I created the title and put "app_random_service_providers" and it looks like i did a mistake :slight_smile:
    Now my website is broken. In each page i have:
    Fatal error: Cannot redeclare process_random_service_providers_shortcode() (previously declared in /home/wtqrfzio/public_html/wp-content/plugins/code-snippets/code-snippets.php(1103) : eval()'d code:2) in /home/wtqrfzio/public_html/wp-content/plugins/code-snippets/code-snippets.php(1103) : eval()'d code on line 159
    i even can't access to my backup :disappointed:
    I'm sur i did the wrong thing with the snippets plugin :slight_frown:
    can you help me please?

  • Jude

    Hi Matheiu

    Thanks for your patience and we're sorry you had to post at multiple places to get this fixed to get this solved.

    Don't worry we'll get this fixed soon. First off I think your database has the old/corrupt values stored and reinstalling the plugin wont be of much help.

    Do you have a backup of the database before you made any of these changes ? Can you share it with us ?

    Other wise can you log in on the command line and do a mysql dump of the WordPress table and send the .sql file over ? I will go through what has changed and help you with a fix.

    You can follow instructions from here if you have doubts

    http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html

    Also once thats done i'll take a look at the code you already have and see if its feasible to provide this feature as a custom solution for you

    Cheers
    Jude

  • Mathieu

    Hi,
    thank for your support.
    So, as i am a bit curious and i want to learn things, i did (for the first time) a restore of the backups (i use the plugin "backupwordpress").
    well, just that you know, it didn't solved the problem :slight_smile:

    so, here is the backup (04/12/14, before the problem) and, about the mysql thingy.... it's a bit too technical for me and difficult to understand. I asked the "Planethoster" support (my website hoster) and i think that i'm giving you the good file, here.

    Thanks
    Mathieu

  • Jude

    Hi Mathieu,

    Thanks for the prompt reply. I went through the data you sent in, I am just looking at one small problem with your request. What if a client selects a time slot where there are no available service providers?

    Also for me to fix this I will need some details from you. Can you please send in:

    - Mark to my attention - Attn: Jude Rosario
    - Link back to this thread
    - Include admin/network access (WordPress admin username/password)
    - Include cPanel/WHM (I will need to look at the DB so need PHPMyAdmin or similar)
    - Include FTP
    - Include MySQL root username and password

    On the contact form, select "I have a different question", this ensures it comes through and gets assigned to me.

  • Mathieu

    Hi Jude,
    Thank you for your help

    So your fist note is very interesting. The planning must show ONLY time slots when a service provider is available. Any of them (they all do the same job)

    To make it very clear, here is the process i need for the client:

    1. Select Service
    2. Select day and time slot
    3. The service provider is automatcly and randomly selected. It's better if this step is NOT SEEN by the client. He can just know who is the provider when he receive the confirmation email.

    Sorry for my english, i'm french.
    I hope i've been clear.
    In order not to work loosing your time, don't hesitate to ask me again to explain anything.

    I sent you the personnal email as you asked

    Thank you so much
    Mathieu

  • Mathieu

    Hi Jude!
    Thank you for your great reactivity

    So, yes, it's what i need.

    In order to continue the tests:
    i created 2 more service providers so that they are 4 now: Mathieu, Claire, Monsieur Auto... et Madame Auto...:
    Mathieu doesn't work on monday
    Claire doesn't work on tuesday,
    Monsieur Auto... doesn't work on wednesday
    Madame Auto.. doesn't work en friday
    non of the work on sunday
    (all this is for testing)
    (Actually... when the business will begin for real, we'll use the google agenda sync so that the providers manage their own schedule as they want.)

    So, it would be perfect if, once you book a time slot, an available provider is automaticly and randomly chosen. And at the same time this chosen provider receive the email and has his schedule booked AND, the client receive the confirmation email with the name of the randomly chosen provider.
    Cause, right now i received the email like: "our staff will do the appointement". I would prefer for example: "Claire will do the appointement"

    last but not least:
    the best of the best would be that Claire and Mathieu are randomly chosen FIRST
    If they are available, those two providers must work more than the others

    So... here are a few examples:
    if all the providers are available at the same time, the random choice must be done first between Claire and Mathieu, then, if they are not available, the random choice will be between other providers
    If Claire and Monsieur Auto are available at the same moment, Claire must be chosen first
    If Mathieu and Claire are available at the same moment, the choice must be completely random
    If Monsieur Auto and Madame Auto are available at the same moment, the choice must be completely random too

    So the priority in the random choice is something like this
    Claire and Mathieu are equal but superior to all the other providers which are equal between them.

    I hope i've been clear.

    And... you asked me to help you with the language... don't hesitate to ask anything. And if you want to put temporary the website in English, you can do it, i'll deal with it withoit any problem

    Thank you very much
    Mathieu

  • Jude

    Hey Mathieu,

    That was just testing code which I left on the site, I later realized its better to test locally on my English site and port the working code to your live site.

    I agree that the client should not see [app_random_service_providers autorefresh = "1"]. I have re-written the function so that it hooks invisibly and adds code via AJAX. Hope this helps.

    You can test your site now. :slight_smile: It works exactly as you asked. I have created a site specific plugin with the required functions so you need not do anything for it to work.

    I am posting the commented code in the next post, if you have any modifications you can make them to this code and copy/paste into your plugin file.

    I have cleaned up the tables and other temp settings I created on your site. Please change all passwords including cPanel, FTP and MySQL at the earliest

    I tried to see if there is an easy way to do the second part of your request for a priority system. Unfortunately It requires modifications to the database and requires a lot of code and must be done as a separate add on preferably. I will note it down as a feature request, but if you require it urgently you can try our Job Board

    Cheers
    Jude

  • Jude

    Here is the code that I added to the site for this functionality

    add_filter('app_pre_confirmation_reply', 'select_random_provider');
    
    function select_random_provider($reply_array)
    {
    // Return if worker is already selected
    	if(''!==$reply_array['worker'])
    		return $reply_array;
    
    // Read in the $value params from the $_POST request
    global $appointments;
    	$appointments = new Appointments();
    	$value = isset($_POST['value']) ? $_POST['value']:"";
    
    		$values 		= explode( ":", $_POST["value"] );
    		$location 		= $values[0];
    		$service 		= $values[1];
    		$worker 		= $values[2];
    		$start 			= $values[3];
    		$end 			= $values[4];
    		$post_id		= $values[5];
    
    	$html = "";
    	$available_workers = array();
    // Get all workers who can perform this service and are available during the current week
    	$all_workers = $appointments->get_workers_by_service($service);
    	$week= date( "W", $start );
    
    	foreach ($all_workers as $w) {
    		$available = true;
    		// Check if this worker has other appointments in this slot
    		$apps = $appointments->get_reserve_apps_by_worker(" ", $w->ID, $week );
    			foreach ( $apps as $app ) {
    				if ( $start >= strtotime( $app->start )
    				  && $end <= strtotime( $app->end ) )
    						$available = false;
    			}
    			// If the worker is add him to our pool of available workers
    			if($available)
    				array_push($available_workers,$w);
    
    	}
    
    // Choose a worker randomly from the pool
    $worker = array_rand($available_workers);
    $worker_id = $available_workers[$worker]->ID; 
    
    // A script that handles AJAX responses and injects the random service provider into the final value param
    $script = <<<EOT
    			<script type="text/javascript">
    				jQuery(document).ready(function($) {
    				var final_value = $(".appointments-confirmation-final-value")
    				tmp = final_value.val().split(':')
    				tmp[2]={$worker_id}
    				final_value.val(tmp.join(":"))
    				})
    			</script>
    EOT;
    
    // Add this script to the $reply_array
    	$html .= $script;
    	$reply_array['worker'] =  $html;
    	// Hook for further development if needed
    	apply_filters('random_service_provider',$reply_array)
    
    	return $reply_array;
    }
  • Mathieu

    Hi Jude,

    Thank you so much. This is really great!
    You did a good and "clean" work, thank you very much.

    About my second request (priority sytem), i can wait one or 2 months... Do you think i should ask to the job board?

    And last question:
    when i create a backup of my website with UpDraftPlus Backup (this plugin does backup "files andd database"), does it save what you created? the code? should i do anything else to backup correctly?
    (sorry, i'm a begginer...)

    Thank you and merry chritmas! :stuck_out_tongue:

  • aristath

    Hello again @Mathieu, I hope you're well today!

    About my second request (priority sytem), i can wait one or 2 months... Do you think i should ask to the job board?

    Yes, that would be preferable. :slight_smile:

    when i create a backup of my website with UpDraftPlus Backup (this plugin does backup "files andd database"), does it save what you created? the code? should i do anything else to backup correctly?

    If your plugin says it also backups the code then you should be fine and these modifications will be backed up.
    In case something goes wrong, the code is still on my colleague's response above so we can re-apply it if needed in the future. :slight_smile:

    Cheers,
    Ari.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.